add-slowdown 1.0 KB

123456789101112131415161718192021222324252627282930313233
  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. fn extract {|line|
  7. # Extract the name and ns/op of a benchmark entry.
  8. var fields = [(re:split '\s+' $line)]
  9. if (not (eq $fields[-1] ns/op)) {
  10. fail 'Last column of '(repr $line)' not ns/op'
  11. }
  12. put $fields[0] $fields[-2]
  13. }
  14. var native = [&]
  15. each {|line|
  16. if (re:match Native $line) {
  17. # Remember the result so that it can be used later.
  18. var name data = (extract $line)
  19. set native[$name] = $data
  20. } elif (re:match Persistent $line) {
  21. # Calculate slowdown and append to the end of the line.
  22. var name data = (extract $line)
  23. var native-name = (re:replace Persistent Native $name)
  24. if (not (has-key $native $native-name)) {
  25. fail 'Native counterpart for '$name' not found'
  26. }
  27. set line = $line' '(printf '%.2f' (/ $data $native[$native-name]))'x'
  28. }
  29. echo $line
  30. }