A minimalist programming language designed for ultra-fast execution with operations completing in 70 nanoseconds to 9 milliseconds.
# K2 Example
x = 10
y = 20
sum = x + y
print sum
# Execution time: 70 nanoseconds
Execute operations in 70-9000 nanoseconds, making K2 one of the fastest interpreted languages.
Minimal footprint with the entire interpreter under 30KB, perfect for resource-constrained environments.
Clean, intuitive syntax that's easy to learn and use, focusing on readability and performance.
Integrated execution time measurement for performance monitoring and optimization.
Run programs from files or execute single expressions directly from the command line.
Zero external dependencies, making installation and deployment simple across platforms.
K2 is designed for speed. Here's how it compares to other languages:
Fastest operation
Average operation
Complex operations
Operation | K2 | Python | JavaScript | Ruby |
---|---|---|---|---|
Variable assignment | 100-400 ns | ~10,000 ns | ~5,000 ns | ~15,000 ns |
Integer addition | 70-200 ns | ~8,000 ns | ~3,000 ns | ~12,000 ns |
Print operation | 1,000-2,000 ns | ~50,000 ns | ~30,000 ns | ~60,000 ns |
Complex expression | 300-5,000 ns | ~100,000 ns | ~80,000 ns | ~150,000 ns |
Experience the next generation of K2 programming with our new Nahir UI framework.
Nahir UI components render in microseconds, providing instant visual feedback and smooth animations.
Build complex interfaces with reusable, composable components that maintain K2's performance benefits.
Utilizes the new K2 ramdisk cache system for ultra-fast component state management and rendering.
Automatically adapts to any screen size with zero performance penalty, perfect for mobile applications.
# Nahir UI Component Example
component Button {
props = {
text: "Click Me",
color: "blue",
onClick: null
}
render {
element = "button"
style = {
background: props.color,
padding: "10px 20px",
borderRadius: "4px"
}
content = props.text
events = {
click: props.onClick
}
}
}
# Create and render a button
myButton = Button.new({
text: "Submit",
color: "green",
onClick: function() {
print "Button clicked!"
}
})
UI.render(myButton)
Interactive preview of the Nahir UI component system
Build powerful native desktop applications with our high-performance GTK4-based GUI library.
Create applications that look and feel native on Linux, Windows, and macOS with the performance of compiled code.
Designed specifically for K2, the API is intuitive and easy to learn, making GUI development accessible to everyone.
Create complex user interfaces with flexible box and grid layouts that adapt to different screen sizes.
Respond to user interactions with a simple callback system that makes event handling straightforward.
# K2 GTK GUI - Hello World Example
import GtkGui
# Create a new application
app = GtkGui.Application.new("org.k2lang.gtkgui.hello", "Hello World")
# Create a window
window = GtkGui.Window.new(app, "Hello World", 400, 300)
# Create a vertical layout container
layout = GtkGui.Box.new()
layout.setOrientation(GtkGui.ORIENTATION_VERTICAL)
layout.setSpacing(20)
layout.setMargin(20)
# Create a heading label
heading = GtkGui.Label.new()
heading.setText("Hello, World!")
heading.setProperty("markup", "Hello, World!")
# Create a button
button = GtkGui.Button.new()
button.setLabel("Click Me")
# Add event listener to the button
button.setCallback("clicked", function(widget) {
GtkGui.Dialog.showMessage(window, "Hello", "You clicked the button!")
})
# Add components to the layout
layout.add(heading)
layout.add(button)
# Set the window content
window.setContent(layout)
# Show the window
window.show()
# Start the application
app.run()
Preview of a native desktop application built with K2 GTK GUI
# Basic K2 program
x = 42
print x
42 Execution time: 1230 nanoseconds
This simple example shows variable assignment and printing. K2 automatically displays execution time.
# Arithmetic operations
a = 10
b = 5
sum = a + b
diff = a - b
product = a * b
quotient = a / b
print sum
print diff
print product
print quotient
15 Execution time: 1150 nanoseconds 5 Execution time: 1120 nanoseconds 50 Execution time: 1130 nanoseconds 2 Execution time: 1140 nanoseconds
K2 supports all basic arithmetic operations with extremely fast execution times.
# Fibonacci sequence
a = 0
b = 1
print a
print b
c = a + b
print c
a = b
b = c
c = a + b
print c
a = b
b = c
c = a + b
print c
0 1 1 2 3
This example calculates the first few numbers in the Fibonacci sequence, demonstrating variable reassignment.
# Execution time control
x = 100
y = 200
# Show execution time
print x + y
# Disable execution time display
show_exec_time off
print x * y
# Enable execution time display
show_exec_time on
print x - y
300 Execution time: 1250 nanoseconds 20000 -100 Execution time: 1180 nanoseconds
K2 allows you to toggle execution time display, which is useful for benchmarking and performance analysis.
Try K2 directly in your browser without installing anything. Write your code and see the results instantly.
// Output will appear here when you run your code
This online runner executes your K2 code using the same precompiled x86_64 binary that powers the desktop version, providing authentic performance metrics.
Experience K2's nanosecond-level execution speed directly in your browser. The code is executed on our servers using optimized native binaries.
All code is executed in an isolated environment with strict resource limits and security controls to ensure safety.
Installing K2 is simple and straightforward:
# Download the package
git clone https://github.com/JJPEOPLES/k2lang.git
cd k2lang
# Compile
g++ -std=c++17 -O3 k2.cpp -o k2
# Install globally (optional)
sudo cp k2 /usr/local/bin/
For Debian/Ubuntu/Kali Linux users, you can use the provided Debian package:
sudo dpkg -i k2-language_1.0.0-1_amd64.deb
Running K2 programs is easy:
# Run a K2 program file
k2 program.k2
# Execute a single expression
k2 -e "print 100 + 200"
K2 has a clean, minimal syntax:
#
=
print
Variables in K2 store integer values:
# Variable assignment
x = 10
y = 20
# Using variables
z = x + y
K2 supports these arithmetic operations:
a + b
a - b
a * b
a / b
Special commands in K2:
Prime (also known as Tera) is the creator of the K2 and K3 programming languages. A passionate developer and systems thinker, Prime focuses on building ultra-fast, minimal, and expressive tools for the next generation of programmers. From compiler design to full-stack deployment, Prime engineers every piece with care, precision, and blazing performance in mind.