Skip to content

Commit

Permalink
Merge pull request sampsyo#287 from jpramos-me/bd-benchmark
Browse files Browse the repository at this point in the history
birthday paradox benchmark
  • Loading branch information
sampsyo authored Sep 7, 2023
2 parents 43895fc + 678e67c commit 4923027
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
47 changes: 47 additions & 0 deletions benchmarks/core/birthday.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ARGS: 23
@main(n: float) {
v0: float = id n;
c: float = call @probability v0;
c: float = id c;
v1: float = id c;
print v1;
v2: int = const 0;
}
@probability(n: float): float {
v0: float = const 1;
prob: float = id v0;
v2: float = const 1;
i: float = id v2;
.for.cond.1:
v3: float = id i;
v4: float = id n;
v5: bool = flt v3 v4;
br v5 .for.body.1 .for.end.1;
.for.body.1:
v6: float = const 365;
v7: float = id i;
v8: float = fsub v6 v7;
log: float = id v8;
v9: float = id log;
v10: float = const 365;
v11: float = fdiv v9 v10;
logUpdated: float = id v11;
v12: float = id prob;
v13: float = id logUpdated;
v14: float = fmul v12 v13;
prob: float = id v14;
v15: float = id i;
v16: float = const 1;
v17: float = fadd v15 v16;
i: float = id v17;
jmp .for.cond.1;
.for.end.1:
v18: float = const 1;
v19: float = id prob;
v20: float = const 100;
v21: float = fmul v19 v20;
v22: float = const 100;
v23: float = fdiv v21 v22;
v24: float = fsub v18 v23;
ret v24;
}
1 change: 1 addition & 0 deletions benchmarks/core/birthday.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.50729723432398566
1 change: 1 addition & 0 deletions benchmarks/core/birthday.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 484
2 changes: 2 additions & 0 deletions docs/tools/bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The current benchmarks are:
* `armstrong`: Determines if the input is an [Armstrong number][armstrong], a number that is the sum of its own digits each raised to the power of the number of digits.
* `binary-fmt`: Print the binary format for the given positive integer.
* `binary-search`: Search a target integer within an integer array, outputs the index of target.
* `birthday`: Simulation of the [birthday][birthday] paradox with an input of `n` people in a given room.
* `bitwise-ops`: Computes the OR, AND, or XOR between two 64-bit integers. (Three modes: 0 = AND, 1 = OR, 2 = XOR)
* `bitshift`: Computes the LEFTSHIFT and RIGHTSHIFT for any integer, also implements an efficient pow function for integers
* `bubblesort`: Sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.
Expand Down Expand Up @@ -75,6 +76,7 @@ The current benchmarks are:

Credit for several of these benchmarks goes to Alexa VanHattum and Gregory Yauney, who implemented them for their [global value numbering project][gvnblog].

[birthday]: https://en.wikipedia.org/wiki/Birthday_problem
[cgroup]: https://en.wikipedia.org/wiki/Cyclic_group#Cyclically_ordered_groups
[fizzbuzz]: https://wiki.c2.com/?FizzBuzzTest
[qf]: https://en.wikipedia.org/wiki/Quadratic_formula
Expand Down

0 comments on commit 4923027

Please sign in to comment.