Tyler Hillery
Tyler Hillery
Explore posts from servers
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
Sounds good, I got what I wanted out of this which was to try out Mojo 🙂
67 replies
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
results on machine
➜ ../run.sh

Benchmarking C
Benchmark 1: ./c/code 40
Time (mean ± σ): 505.8 ms ± 0.4 ms [User: 504.1 ms, System: 1.2 ms]
Range (min … max): 505.5 ms … 506.2 ms 3 runs


Benchmarking Rust
Benchmark 1: ./rust/target/release/code 40
Time (mean ± σ): 504.5 ms ± 0.4 ms [User: 502.6 ms, System: 1.2 ms]
Range (min … max): 504.0 ms … 504.9 ms 3 runs


Benchmarking Zig
Benchmark 1: ./zig/code 40
Time (mean ± σ): 501.9 ms ± 0.4 ms [User: 500.1 ms, System: 1.2 ms]
Range (min … max): 501.7 ms … 502.4 ms 3 runs


Benchmarking Mojo
Benchmark 1: ./mojo/code 40
Time (mean ± σ): 2.7 ms ± 0.1 ms [User: 1.7 ms, System: 0.7 ms]
Range (min … max): 2.7 ms … 2.8 ms 3 runs
➜ ../run.sh

Benchmarking C
Benchmark 1: ./c/code 40
Time (mean ± σ): 505.8 ms ± 0.4 ms [User: 504.1 ms, System: 1.2 ms]
Range (min … max): 505.5 ms … 506.2 ms 3 runs


Benchmarking Rust
Benchmark 1: ./rust/target/release/code 40
Time (mean ± σ): 504.5 ms ± 0.4 ms [User: 502.6 ms, System: 1.2 ms]
Range (min … max): 504.0 ms … 504.9 ms 3 runs


Benchmarking Zig
Benchmark 1: ./zig/code 40
Time (mean ± σ): 501.9 ms ± 0.4 ms [User: 500.1 ms, System: 1.2 ms]
Range (min … max): 501.7 ms … 502.4 ms 3 runs


Benchmarking Mojo
Benchmark 1: ./mojo/code 40
Time (mean ± σ): 2.7 ms ± 0.1 ms [User: 1.7 ms, System: 0.7 ms]
Range (min … max): 2.7 ms … 2.8 ms 3 runs
67 replies
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
what sort of wizardary is this
67 replies
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
I'm not adamant on submitting PR, thought it was just a fun way to try out Mojo, if you rather have me not submit that's fine by me. I still think these are awesome results ( speaking as a python dev )
67 replies
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
That seemed to help!
➜ ../run.sh

Benchmarking C
Benchmark 1: ./c/code 40
Time (mean ± σ): 505.6 ms ± 0.1 ms [User: 503.9 ms, System: 1.1 ms]
Range (min … max): 505.5 ms … 505.7 ms 3 runs


Benchmarking Rust
Benchmark 1: ./rust/target/release/code 40
Time (mean ± σ): 504.5 ms ± 0.2 ms [User: 502.7 ms, System: 1.2 ms]
Range (min … max): 504.3 ms … 504.8 ms 3 runs


Benchmarking Zig
Benchmark 1: ./zig/code 40
Time (mean ± σ): 501.7 ms ± 0.3 ms [User: 500.2 ms, System: 1.0 ms]
Range (min … max): 501.3 ms … 502.0 ms 3 runs


Benchmarking Mojo
Benchmark 1: ./mojo/code 40
Time (mean ± σ): 607.4 ms ± 0.3 ms [User: 605.7 ms, System: 1.8 ms]
Range (min … max): 607.2 ms … 607.7 ms 3 runs
➜ ../run.sh

Benchmarking C
Benchmark 1: ./c/code 40
Time (mean ± σ): 505.6 ms ± 0.1 ms [User: 503.9 ms, System: 1.1 ms]
Range (min … max): 505.5 ms … 505.7 ms 3 runs


Benchmarking Rust
Benchmark 1: ./rust/target/release/code 40
Time (mean ± σ): 504.5 ms ± 0.2 ms [User: 502.7 ms, System: 1.2 ms]
Range (min … max): 504.3 ms … 504.8 ms 3 runs


Benchmarking Zig
Benchmark 1: ./zig/code 40
Time (mean ± σ): 501.7 ms ± 0.3 ms [User: 500.2 ms, System: 1.0 ms]
Range (min … max): 501.3 ms … 502.0 ms 3 runs


Benchmarking Mojo
Benchmark 1: ./mojo/code 40
Time (mean ± σ): 607.4 ms ± 0.3 ms [User: 605.7 ms, System: 1.8 ms]
Range (min … max): 607.2 ms … 607.7 ms 3 runs
67 replies
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
➜ ../run.sh

Benchmarking C
Benchmark 1: ./c/code 40
Time (mean ± σ): 507.1 ms ± 1.0 ms [User: 505.2 ms, System: 1.4 ms]
Range (min … max): 506.1 ms … 508.0 ms 3 runs


Benchmarking Rust
Benchmark 1: ./rust/target/release/code 40
Time (mean ± σ): 504.6 ms ± 0.8 ms [User: 502.8 ms, System: 1.3 ms]
Range (min … max): 503.8 ms … 505.4 ms 3 runs


Benchmarking Zig
Benchmark 1: ./zig/code 40
Time (mean ± σ): 503.2 ms ± 0.5 ms [User: 501.1 ms, System: 1.5 ms]
Range (min … max): 502.8 ms … 503.8 ms 3 runs


Benchmarking Mojo
Benchmark 1: ./mojo/code 40
Time (mean ± σ): 764.5 ms ± 0.1 ms [User: 762.4 ms, System: 2.1 ms]
Range (min … max): 764.4 ms … 764.5 ms 3 runs
➜ ../run.sh

Benchmarking C
Benchmark 1: ./c/code 40
Time (mean ± σ): 507.1 ms ± 1.0 ms [User: 505.2 ms, System: 1.4 ms]
Range (min … max): 506.1 ms … 508.0 ms 3 runs


Benchmarking Rust
Benchmark 1: ./rust/target/release/code 40
Time (mean ± σ): 504.6 ms ± 0.8 ms [User: 502.8 ms, System: 1.3 ms]
Range (min … max): 503.8 ms … 505.4 ms 3 runs


Benchmarking Zig
Benchmark 1: ./zig/code 40
Time (mean ± σ): 503.2 ms ± 0.5 ms [User: 501.1 ms, System: 1.5 ms]
Range (min … max): 502.8 ms … 503.8 ms 3 runs


Benchmarking Mojo
Benchmark 1: ./mojo/code 40
Time (mean ± σ): 764.5 ms ± 0.1 ms [User: 762.4 ms, System: 2.1 ms]
Range (min … max): 764.4 ms … 764.5 ms 3 runs
67 replies
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
let me set those up real quick
67 replies
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
Updated results using code above and switching to nightly. My machine is different than the one used in the official repo as well.
➜ bash ../run.sh

Benchmarking Mojo
Benchmark 1: ./mojo/code 40
Time (mean ± σ): 774.5 ms ± 10.0 ms [User: 767.7 ms, System: 3.0 ms]
Range (min … max): 767.6 ms … 786.0 ms 3 runs

➜ magic run mojo --version
mojo 24.6.0.dev2024120416 (36394a81)
➜ bash ../run.sh

Benchmarking Mojo
Benchmark 1: ./mojo/code 40
Time (mean ± σ): 774.5 ms ± 10.0 ms [User: 767.7 ms, System: 3.0 ms]
Range (min … max): 767.6 ms … 786.0 ms 3 runs

➜ magic run mojo --version
mojo 24.6.0.dev2024120416 (36394a81)
67 replies
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
Thanks for the feedback everyone, I had fun dipping my toes into Mojo. I will work on implementing your suggestions and open a PR
67 replies
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
Lot of people making fun of how long python takes, I think it would be nice to show an implementation that looks similar to python to demonstrate how much faster your code is with very little changes
67 replies
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
import sys
import random

fn main() raises:
var size = 10000
var u = atol(sys.argv()[1]) # Get an input number from the command line
var r = int(random.random_ui64(0, size)) # Get a random number 0 <= r < 10k
var a = List[Int]() # Array of 10k elements initialized to 0
for _ in range(size):
a.append(0)
for i in range(10000): # 10k outer loop iterations
for j in range(100000): # 100k inner loop iterations, per outer loop iteration
a[i] += j%u # Simple sum
a[i] += r # Add a random value to each element in array
print(a[r]) # Print out a single element from the array
import sys
import random

fn main() raises:
var size = 10000
var u = atol(sys.argv()[1]) # Get an input number from the command line
var r = int(random.random_ui64(0, size)) # Get a random number 0 <= r < 10k
var a = List[Int]() # Array of 10k elements initialized to 0
for _ in range(size):
a.append(0)
for i in range(10000): # 10k outer loop iterations
for j in range(100000): # 100k inner loop iterations, per outer loop iteration
a[i] += j%u # Simple sum
a[i] += r # Add a random value to each element in array
print(a[r]) # Print out a single element from the array
67 replies
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
➜ magic --version
magic 0.5.0 - (based on pixi 0.37.0)

➜ magic run mojo --version
mojo 24.5.0 (e8aacb95)
➜ magic --version
magic 0.5.0 - (based on pixi 0.37.0)

➜ magic run mojo --version
mojo 24.5.0 (e8aacb95)
67 replies
MModular
Created by Tyler Hillery on 12/4/2024 in #questions
1 Billion nested loop iterations Mojo Implementation - seeking feedback
here are my results
languages/loops git:(tyler/feat/add-mojo) ✗
➜ neofetch
'c.
.OMMMMo ------------------------------
OMMM0, OS: macOS 14.6.1 23G93 arm64
.;loddo:' loolloddol;. Host: Mac15,3
cKMMMMMMMMMMNWMMMMMMMMMM0: Kernel: 23.6.0
.KMMMMMMMMMMMMMMMMMMMMMMMWd. Uptime: 3 days, 2 hours, 39 mins
XMMMMMMMMMMMMMMMMMMMMMMMX. Packages: 56 (brew)
;MMMMMMMMMMMMMMMMMMMMMMMM: Shell: zsh 5.9
:MMMMMMMMMMMMMMMMMMMMMMMM: Resolution: 2560x1440, 1512x982
.MMMMMMMMMMMMMMMMMMMMMMMMX. DE: Aqua
kMMMMMMMMMMMMMMMMMMMMMMMMWd. WM: Rectangle
.XMMMMMMMMMMMMMMMMMMMMMMMMMMk Terminal: vscode
.XMMMMMMMMMMMMMMMMMMMMMMMMK. CPU: Apple M3
kMMMMMMMMMMMMMMMMMMMMMMd GPU: Apple M3
;KMMMMMMMWXXWMMMMMMMk. Memory: 4251MiB / 24576MiB
.cooc,. .,coo:.




languages/loops git:(tyler/feat/add-mojo)
➜ bash ../compile.sh
languages/loops git:(tyler/feat/add-mojo) ✗
➜ bash ../run.sh

Benchmarking Mojo
Benchmark 1: ./mojo/code 40
Time (mean ± σ): 778.6 ms ± 10.9 ms [User: 769.5 ms, System: 3.6 ms]
Range (min … max): 769.9 ms … 790.8 ms 3 runs
languages/loops git:(tyler/feat/add-mojo) ✗
➜ neofetch
'c.
.OMMMMo ------------------------------
OMMM0, OS: macOS 14.6.1 23G93 arm64
.;loddo:' loolloddol;. Host: Mac15,3
cKMMMMMMMMMMNWMMMMMMMMMM0: Kernel: 23.6.0
.KMMMMMMMMMMMMMMMMMMMMMMMWd. Uptime: 3 days, 2 hours, 39 mins
XMMMMMMMMMMMMMMMMMMMMMMMX. Packages: 56 (brew)
;MMMMMMMMMMMMMMMMMMMMMMMM: Shell: zsh 5.9
:MMMMMMMMMMMMMMMMMMMMMMMM: Resolution: 2560x1440, 1512x982
.MMMMMMMMMMMMMMMMMMMMMMMMX. DE: Aqua
kMMMMMMMMMMMMMMMMMMMMMMMMWd. WM: Rectangle
.XMMMMMMMMMMMMMMMMMMMMMMMMMMk Terminal: vscode
.XMMMMMMMMMMMMMMMMMMMMMMMMK. CPU: Apple M3
kMMMMMMMMMMMMMMMMMMMMMMd GPU: Apple M3
;KMMMMMMMWXXWMMMMMMMk. Memory: 4251MiB / 24576MiB
.cooc,. .,coo:.




languages/loops git:(tyler/feat/add-mojo)
➜ bash ../compile.sh
languages/loops git:(tyler/feat/add-mojo) ✗
➜ bash ../run.sh

Benchmarking Mojo
Benchmark 1: ./mojo/code 40
Time (mean ± σ): 778.6 ms ± 10.9 ms [User: 769.5 ms, System: 3.6 ms]
Range (min … max): 769.9 ms … 790.8 ms 3 runs
67 replies