
Mojo Has a Free API: Python Syntax With C++ Performance
What if Python was 68,000x faster? Not a typo. Mojo achieves C/C++ performance with Python syntax. What Is Mojo? Mojo is a programming language that's a superset of Python — your existing Python code runs in Mojo — but adds systems programming features that make it as fast as C. # This is valid Mojo AND valid Python def hello (): print ( " Hello from Mojo! " ) # But Mojo adds performance features fn fast_hello (): print ( " Hello from fast Mojo! " ) def works like Python (dynamic). fn is Mojo-specific (static, fast). The Performance # Mojo struct with SIMD operations struct Matrix: var data: DTypePointer[DType.float64] var rows: Int var cols: Int fn __init__(inout self, rows: Int, cols: Int): self.rows = rows self.cols = cols self.data = DTypePointer[DType.float64].alloc(rows * cols) fn matmul(self, other: Matrix) -> Matrix: var result = Matrix(self.rows, other.cols) @parameter fn calc_row(i: Int): for j in range(other.cols): var sum: Float64 = 0 @parameter fn dot[simd_width: Int](k: I
Continue reading on Dev.to Python
Opens in a new tab


