Skip to content

Commit abaf99b

Browse files
committed
polish criterionmethodology.py
1 parent 79f4b3e commit abaf99b

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

benchmarks/scripts/criterion-drop-in-replacement/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This directory contains a Python re-implementation of the Haskell Criterion methodology to run executables (instead of Haskell functions, like Criterion normally does).
44
One could call it "benchrunner-runner" because the purpose is to run `benchrunner` many times and calculate the appropriate run time statistics.
55

6-
We take as input some program `prog` with the following interface:
6+
We take as input a path to some program `prog` (meant to be the `benchrunner`) with the following interface:
77

88
- `prog` takes `iters` as a command-line argument,
99
- `prog` measures run time of a function of interest in a tight loop that repeats `iters` many times, and finally
@@ -29,7 +29,7 @@ will call `benchrunner iters Quicksort Seq 2000` for various `iters`.
2929

3030
`sweep_seq` performs a logarithmic sweep over different array sizes, invoking `criterionmethdology.py` at each point.
3131

32-
## Arightmetic vs geometric mean
32+
## Arithmetic vs geometric mean
3333

3434
Since performance data is non-negative and judged multiplicatively (twice as good means numbers are half, twice has bad means numbers are doubled; these are all *factors*), the geomean and geo-standard-deviation may make more sense theoretically.
3535
However, from some testing, the geomean seems to vary wildly for programs with fleeting execution times, even between repeated runs with the same parameters.

benchmarks/scripts/criterion-drop-in-replacement/criterionmethodology.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def linear_regression_with_std(x, y):
2424
return slope, intercept, std_dev
2525

2626
def do_bench(cliargs, iters):
27-
print([cliargs[1], str(iters)] + cliargs[2:])
27+
bin = cliargs[1].rsplit('/', 1)[-1]
28+
print([bin] + cliargs[2:] + [str(iters)])
2829
out = str(subprocess.check_output([cliargs[1], str(iters)] + cliargs[2:]))
2930
s1 = out[out.find("SELFTIMED")+11:]
3031
s2 = float(s1[:s1.find("\n")-4])
@@ -34,7 +35,7 @@ def do_bench(cliargs, iters):
3435
b2 = float(b1[:b1.find("SELFTIMED")-2])
3536
batchtime = b2
3637

37-
print(f"ITERS: {iters}, BATCHTIME: {batchtime}, SELFTIMED: {selftimed}")
38+
#print(f"ITERS: {iters}, BATCHTIME: {batchtime}, SELFTIMED: {selftimed}")
3839
return batchtime
3940

4041
def converge(cliargs):
@@ -65,17 +66,20 @@ def converge(cliargs):
6566
st = do_bench(cliargs, iters)
6667
xs.append(iters)
6768
ys.append(st)
68-
m, b, sigma = linear_regression_with_std(xs, ys)
69-
print(f"Slope (Mean): {m}, Intercept (Overhead): {b}, Stdev: {sigma}")
69+
70+
m, b, sig = linear_regression_with_std(xs, ys)
7071
p, lnc, lngsd = linear_regression_with_std([math.log(x) for x in xs], [math.log(y) for y in ys])
7172
c, gsd = math.exp(lnc), math.exp(lngsd)
72-
print(f"Power (Distortion): {p}, Factor (Geomean) {c}, GeoStdev {gsd}")
73+
74+
print(f"Slope (Mean): {m:.2e}, Stdev: {sig:.2e}, Intercept (Overhead): {b:.2e}")
75+
print(f"Factor (Geomean): {c:.2e}, GeoStdev: {gsd:.2e}, Power (Distortion): {p:.2e}")
76+
7377
if MAKE_PLOT:
7478
plt.plot(xs, ys, 'rx')
7579
plt.plot([xs[0], xs[-1]], [m*xs[0]+b, m*xs[-1]+b], color="blue")
7680
plt.plot(xs, [c*x**p for x in xs], color="green")
7781
plt.savefig("plot.png")
78-
return m, sigma, c, gsd
82+
return m, sig, c, gsd
7983

8084
if __name__ == "__main__":
81-
print(converge(argv))
85+
converge(argv)

0 commit comments

Comments
 (0)