File: add-slowdown

package info (click to toggle)
elvish 0.21.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,372 kB
  • sloc: javascript: 236; sh: 130; python: 104; makefile: 88; xml: 9
file content (33 lines) | stat: -rwxr-xr-x 1,069 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env elvish
# Parse an output of "go test -bench .", annotating benchmark results for
# persistent operations with the slowdown ratio compared to their native
# counterparts.
use re

fn extract {|line|
    # Extract the name and ns/op of a benchmark entry.
    var fields = [(re:split '\s+' $line)]
    if (not (eq $fields[-1] ns/op)) {
        fail 'Last column of '(repr $line)' not ns/op'
    }
    put $fields[0] $fields[-2]
}

var native = [&]

each {|line|
    if (re:match Native $line) {
        # Remember the result so that it can be used later.
        var name data = (extract $line)
        set native[$name] = $data
    } elif (re:match Persistent $line) {
        # Calculate slowdown and append to the end of the line.
        var name data = (extract $line)
        var native-name = (re:replace Persistent Native $name)
        if (not (has-key $native $native-name)) {
            fail 'Native counterpart for '$name' not found'
        }
        set line = $line' '(printf '%.2f' (/ $data $native[$native-name]))'x'
    }
    echo $line
}