-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbench10
More file actions
executable file
·44 lines (43 loc) · 2.14 KB
/
bench10
File metadata and controls
executable file
·44 lines (43 loc) · 2.14 KB
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
#!/bin/bash
# bench10 - run a ruby benchmark script 10 times and compare the timings as a
# ratio. The ruby benchmark script must use (or have the same output as) the
# Benchmark.bm or Benchmark.bmbm command.
#
# Usage:
# bench10 <ruby_benchmark_script.rb>
#
# PROTIP: Put your REFERENCE code first, because reasons. (If I ever figure out
# how to make this work with >2 alternatives all compared to a single reference,
# we're gonna want the reference to be in timings[0], narmean?)
#
# Example Benchmark.bmbm output:
# $ ruby keygen_benchmark.rb
# Rehearsal ----------------------------------------------------
# Array with join: 0.190000 0.010000 0.200000 ( 0.230284)
# With Enumerator: 0.480000 0.000000 0.480000 ( 0.518744)
# ------------------------------------------- total: 0.680000sec
#
# user system total real
# Array with join: 0.160000 0.010000 0.170000 ( 0.172731)
# With Enumerator: 0.490000 0.010000 0.500000 ( 0.507471)
# This scriptlet looks for the line with the "real" on it, then grabs the
# numbers in parentheses and prints them as a ratio.
#
# Example Output:
# $ bench10 keygen_benchmark.rb
# 1. 0.143617 / 0.502916 => 0.28556856413397064
# 2. 0.150246 / 0.488346 => 0.3076630094236463
# 3. 0.169519 / 0.553037 => 0.3065237949721266
# 4. 0.162363 / 0.484136 => 0.33536650858436473
# 5. 0.167374 / 0.493827 => 0.3389324601530495
# 6. 0.197403 / 0.691167 => 0.285608253866287
# 7. 0.175552 / 0.618753 => 0.28371902843299346
# 8. 0.199851 / 0.645255 => 0.30972406257991025
# 9. 0.186563 / 0.575400 => 0.32423183872088984
# 10. 0.241346 / 0.713072 => 0.3384595104000718
#
# TODO: Make this work with more than 2 outputs... (Did this. It gets really
# hard to read the output. Better to either write a ruby script to consume the
# benchmark output, or better yet to just write your benchmark script to call
# measure and then play with the Benchmark::Tms objects yourself.)
seq 10 | while read f; do printf '%2d. ' $f; ruby $1 | grep -A 2 real | tail -n 2 | cut -d ':' -f 2 | awk '{ print $5 }' | tr -d ')' | xargs ruby -e 'puts "#{ARGV[1]} / #{ARGV[0]} => #{ARGV[1].to_f/ARGV[0].to_f}"'; done