src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/persistent/add-slowdown (about)

     1  #!/usr/bin/env elvish
     2  # Parse an output of "go test -bench .", annotating benchmark results for
     3  # persistent operations with the slowdown ratio compared to their native
     4  # counterparts.
     5  use re
     6  
     7  fn extract {|line|
     8      # Extract the name and ns/op of a benchmark entry.
     9      var fields = [(re:split '\s+' $line)]
    10      if (not (eq $fields[-1] ns/op)) {
    11          fail 'Last column of '(repr $line)' not ns/op'
    12      }
    13      put $fields[0] $fields[-2]
    14  }
    15  
    16  var native = [&]
    17  
    18  each {|line|
    19      if (re:match Native $line) {
    20          # Remember the result so that it can be used later.
    21          var name data = (extract $line)
    22          set native[$name] = $data
    23      } elif (re:match Persistent $line) {
    24          # Calculate slowdown and append to the end of the line.
    25          var name data = (extract $line)
    26          var native-name = (re:replace Persistent Native $name)
    27          if (not (has-key $native $native-name)) {
    28              fail 'Native counterpart for '$name' not found'
    29          }
    30          set line = $line' '(printf '%.2f' (/ $data $native[$native-name]))'x'
    31      }
    32      echo $line
    33  }