-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_simd.mojo
46 lines (39 loc) · 1.12 KB
/
benchmark_simd.mojo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from benchmark import benchmark
from simd_atol import atol as simd_str_to_uint
alias file_name = "numbers.txt"
alias size = 10000000
fn main() raises:
var numbers = List[String](capacity=size)
var i = 0
with open(file_name, "r") as f:
var number: String = ""
while True:
var c = f.read(1)
if c == "":
break
if c == "\n":
numbers.append(number)
i += 1
number = ""
continue
number += c
print("Finished loading numbers. Loaded", len(numbers))
@parameter
fn run_atol():
for i in range(size):
var number = numbers[i]
try:
_ = atol(number)
except:
print("atol failed")
@parameter
fn run_simd_atol():
for i in range(size):
var number = numbers[i]
try:
_ = simd_str_to_uint(number)
except:
print("simd atol failed")
var report = benchmark.run[run_simd_atol]()
report.print()
_ = numbers