Closed stefreak closed 2 years ago
@kamalmarhubi @jvns do you think it's worth it investing the time to finish this and add it to the curriculum?
Benchmark results:
----> benchmarks/branch.py
rounded iterations: 100000
exact iterations: 103595
final time taken: 1.05427289009
----> benchmarks/branch_mispredictions.py
rounded iterations: 10000
exact iterations: 10512
final time taken: 1.13148808479
I believe run_benchmarks.py
adds the results to the json file, but I get following error in the end:
----> benchmarks/sum.c
Traceback (most recent call last):
File "./run_benchmarks.py", line 91, in <module>
for result in run_benchmarks(all_benchmarks):
File "./run_benchmarks.py", line 66, in run_benchmarks
yield benchmark(source)
File "./run_benchmarks.py", line 34, in benchmark
iters = int(math.ceil(iters))
OverflowError: cannot convert float infinity to integer
How many times in one second can you sort a 500-element array:
Branches can make CPUs slow, if they fail to predict their outcome.
The branches in this example are part of the sorting algorithm: "Is element n bigger than n+1? If yes, change the order!"