1 ;; -*- lexical-binding: t; -*-
3 (defconst context-coloring-benchmark-path
4 (file-name-directory (or load-file-name buffer-file-name)))
6 (defun context-coloring-benchmark-resolve-path (path)
7 (expand-file-name path context-coloring-benchmark-path))
9 (defun context-coloring-benchmark-log-results (result-file fixture)
11 (let ((results-buffer (current-buffer)))
13 (insert (concat fixture "\n"))
14 (prepend-to-buffer results-buffer (point-min) (point-max)))
17 (append-to-buffer results-buffer (point-min) (point-max))))
18 (make-directory (context-coloring-benchmark-resolve-path "./logs") t)
19 (append-to-file nil nil result-file))
21 (defun context-coloring-benchmark-next-tick (function)
22 (run-at-time 0.001 nil function))
24 (defun context-coloring-benchmark-next (list continue stop)
26 (context-coloring-benchmark-next-tick stop)
27 (context-coloring-benchmark-next-tick
33 (context-coloring-benchmark-next (cdr list) continue stop)))))))
35 (defun context-coloring-benchmark-async (title setup teardown fixtures callback)
37 (let ((result-file (context-coloring-benchmark-resolve-path
38 (concat "./logs/results-" title "-" (format-time-string "%s") ".log"))))
39 (context-coloring-benchmark-next
42 (let ((fixture (context-coloring-benchmark-resolve-path path))
47 (lambda (original-function)
51 (setq count (+ count 1))
55 (advice-remove 'context-coloring-colorize advice)
57 (context-coloring-benchmark-log-results
61 (funcall 'context-coloring-colorize)))))))
62 (advice-add 'context-coloring-colorize :around advice)
66 (if callback (funcall callback))))))
68 (defconst context-coloring-benchmark-js-fixtures
69 '("./fixtures/jquery-2.1.1.js"
70 "./fixtures/lodash-2.4.1.js"
71 "./fixtures/async-0.9.0.js"
72 "./fixtures/mkdirp-0.5.0.js"))
74 (defun context-coloring-benchmark-js-mode-setup ()
75 (add-hook 'js-mode-hook 'context-coloring-mode)
76 (elp-instrument-package "context-coloring-"))
78 (defun context-coloring-benchmark-js-mode-teardown ()
79 (remove-hook 'js-mode-hook 'context-coloring-mode))
81 (defun context-coloring-benchmark-js-mode-run (callback)
82 (context-coloring-benchmark-async
84 'context-coloring-benchmark-js-mode-setup
85 'context-coloring-benchmark-js-mode-teardown
86 context-coloring-benchmark-js-fixtures
89 (defun context-coloring-benchmark-js2-mode-setup ()
91 (setq js2-mode-show-parse-errors nil)
92 (setq js2-mode-show-strict-warnings nil)
93 (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
94 (add-hook 'js2-mode-hook 'context-coloring-mode)
95 (elp-instrument-package "context-coloring-"))
97 (defun context-coloring-benchmark-js2-mode-teardown ()
98 (remove-hook 'js2-mode-hook 'context-coloring-mode)
99 (setq auto-mode-alist (delete '("\\.js\\'" . js2-mode)
101 (setq js2-mode-show-strict-warnings t)
102 (setq js2-mode-show-parse-errors t))
104 (defun context-coloring-benchmark-js2-mode-run (callback)
105 (context-coloring-benchmark-async
107 'context-coloring-benchmark-js2-mode-setup
108 'context-coloring-benchmark-js2-mode-teardown
109 context-coloring-benchmark-js-fixtures
112 (defun context-coloring-benchmark-run ()
113 (context-coloring-benchmark-next
114 '(context-coloring-benchmark-js-mode-run
115 context-coloring-benchmark-js2-mode-run)
116 (lambda (function next)
117 (funcall function next))