Skip to content

Commit ab0acab

Browse files
committed
Add stupid benchmark
1 parent 5b8f33f commit ab0acab

File tree

5 files changed

+695
-17
lines changed

5 files changed

+695
-17
lines changed

bench.nu

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
const jar = "fred.jar"
22
const outExe = "bench.bin"
33

4-
export def run [ file: string, lazyMarkScan: bool ] {
4+
export def run [ file: string, lazyMarkScanOnly: bool ] {
55
let benchName = $file | path basename
6-
if $lazyMarkScan {
6+
if $lazyMarkScanOnly {
77
java -jar $jar $file -o $outExe --lazy-mark-scan-only
88
} else {
99
java -jar $jar $file -o $outExe
1010
}
11-
print $"Compiled ($file) \(lazy-mark-scan: ($lazyMarkScan))"
11+
print $"Compiled ($file) \(lazy-mark-scan-only: ($lazyMarkScanOnly))"
12+
let out = ^$"./($outExe)"
13+
print $out
1214
let res = (
13-
^$"./($outExe)"
15+
$out
1416
| lines
15-
| last
1617
| parse "Time stamp counter diff: {tsc}, clock diff: {clock}"
1718
| get 0)
1819
{
19-
name: $benchName,
20-
tsc: $res.tsc,
21-
clock: $res.clock,
22-
lazyMarkScan: $lazyMarkScan
20+
Name: $benchName,
21+
"Timestamp counter": $res.tsc,
22+
Clock: $res.clock,
23+
"Lazy mark scan only": $lazyMarkScanOnly
2324
}
2425
}
2526

2627
export def run-all [ ] {
27-
let files = (ls benchmarks).name
28-
let myAlgo = $files | each { |file| run $file false }
29-
let lazyOnly = $files | each { |file| run $file true }
30-
$myAlgo ++ $lazyOnly
28+
let files = (ls benchmarks/*.fred).name
29+
let results = $files | each { |file| [(run $file false), (run $file true)] }
30+
$results | flatten
3131
}

benchmarks/game.fred

+9-4
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,23 @@ fn createAndDeletePlayers(n: int, store: Store): int =
3030
c("processAllPCRs();");
3131
createAndDeletePlayers(n - 1, store)
3232

33-
fn pointlessLoop(iters: int): int =
33+
fn pointlessLoop(iters: int, store: Store): int =
3434
if iters == 0 then 0
3535
else
36-
createAndDeletePlayers(5000, Store { datums: createDummyData(10000) });
36+
createAndDeletePlayers(10, store);
3737
c("processAllPCRs();");
38-
pointlessLoop(iters - 1)
38+
pointlessLoop(iters - 1, store)
39+
40+
fn run(): int =
41+
let store = Store { datums: createDummyData(1000) } in
42+
pointlessLoop(50000, store);
43+
c("processAllPCRs();")
3944

4045
fn main(): int =
4146
printf("Starting game benchmark\n");
4247
c("float clockStart = (float) clock()/CLOCKS_PER_SEC;");
4348
c("u_int64_t tscStart = rdtscp();");
44-
pointlessLoop(10000);
49+
run();
4550
c("printf(
4651
\"Time stamp counter diff: %ld, clock diff: %lf\",
4752
rdtscp() - tscStart,

benchmarks/gen-stupid.nu

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env nu
2+
3+
# Generate a benchmark where lazy mark scan outperforms my algorithm
4+
# stupid because this has nothing to do with the real world
5+
6+
let numTypes = 200
7+
8+
for type in 0..<$numTypes {
9+
let next = if $type == 0 { "" } else { $", f: T($type - 1)" }
10+
print $"data T($type) = T($type) { mut cyclic: OptT($type)($next) }"
11+
print $"data OptT($type) = SomeT($type) { value: T($type) } | NoneT($type) {}"
12+
}
13+
14+
print $"fn create\(): T($numTypes - 1) ="
15+
let v0 = $"T0 { cyclic: NoneT0 {} }"
16+
print (1..<$numTypes | reduce -f $v0 {|t, acc| $"T($t) { cyclic: NoneT($t) {}, f: ($acc) }" })
17+
18+
print $"fn triggerDecrs\(v: T($numTypes - 1)): int ="
19+
for type in 0..<$numTypes {
20+
let ref = 0..<$type | each { ".f" } | str join
21+
print $"\(let temp($type) = v($ref) in 0);"
22+
}
23+
print "0"
24+
25+
print '
26+
fn runOnce(): int =
27+
let v = create() in
28+
triggerDecrs(v)
29+
30+
fn run(iters: int): int =
31+
if iters == 0 then 0
32+
else
33+
runOnce();
34+
c("processAllPCRs();");
35+
run(iters - 1)
36+
37+
fn main(): int =
38+
printf("Starting stupid benchmark\n");
39+
c("float clockStart = (float) clock()/CLOCKS_PER_SEC;");
40+
c("u_int64_t tscStart = rdtscp();");
41+
run(50000);
42+
c("printf(
43+
\"Time stamp counter diff: %ld, clock diff: %lf\",
44+
rdtscp() - tscStart,
45+
((float) clock()/CLOCKS_PER_SEC) - clockStart);")'

0 commit comments

Comments
 (0)