benchmarking.lisp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ;; Copyright (c) 2008 Accelerated Data Works, Ryan Davis
  2. ;; Permission is hereby granted, free of charge, to any person
  3. ;; obtaining a copy of this software and associated documentation files
  4. ;; (the "Software"), to deal in the Software without restriction,
  5. ;; including without limitation the rights to use, copy, modify, merge,
  6. ;; publish, distribute, sublicense, and/or sell copies of the Software,
  7. ;; and to permit persons to whom the Software is furnished to do so,
  8. ;; subject to the following conditions:
  9. ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  10. ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11. ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  12. ;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  13. ;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  14. ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  15. ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. (require 'cl-ppcre)
  17. (defpackage #:net.acceleration.adw-charting-benchmarking
  18. (:use #:cl))
  19. (in-package #:net.acceleration.adw-charting-benchmarking)
  20. (defun timing-graph ()
  21. (adw-charting:with-line-chart (300 400)
  22. (adw-charting:set-axis :x "series")
  23. (adw-charting:set-axis :y "real time (ms)")
  24. (loop for x from 1 to 3
  25. do
  26. (let ((dp (* 10 x)))
  27. (adw-charting:add-series
  28. (format nil "~ap" dp)
  29. (loop for i from 1 to 20
  30. collect (list i (first (timings i dp)))))
  31. (format T "done with ~a run" dp)))
  32. (adw-charting:save-file "series-real-time.png")
  33. ))
  34. (defun timings (series points)
  35. (let* ((trc (with-output-to-string (*trace-output*)
  36. (time (lines series points))))
  37. (rt (cl-ppcre:register-groups-bind (rt)
  38. ("([\\d\\.]+) seconds of real" trc)
  39. (parse-integer (cl-ppcre:regex-replace-all "\\." rt ""))))
  40. (bc (cl-ppcre:register-groups-bind (rt)
  41. ("([\\d\\,]+) bytes" trc)
  42. (parse-integer (cl-ppcre:regex-replace-all "\\," rt "")))))
  43. (list rt bc)))
  44. (defun lines (num-series points-per-series)
  45. (adw-charting:with-line-chart (300 400)
  46. (dotimes (s num-series)
  47. (adw-charting:add-series (format nil "s~a" s)
  48. (random-series points-per-series
  49. 0 -100 100 100))
  50. )
  51. (adw-charting:save-file "benchmarking")))
  52. (defun random-between (min max)
  53. (+ min
  54. (random (float (- max min)))))
  55. (defun random-point (min-x min-y max-x max-y)
  56. (list (random-between min-x max-x)
  57. (random-between min-y max-y)))
  58. (defun random-series (n min-x min-y max-x max-y)
  59. (sort
  60. (loop for i from 1 to n
  61. collect (random-point min-x min-y max-x max-y))
  62. #'< :key #'first))