]> code.delx.au - gnu-emacs-elpa/blob - benchmark/context-coloring-benchmark.el
4403fe878bb669e0457726a009146e7dfb162ee0
[gnu-emacs-elpa] / benchmark / context-coloring-benchmark.el
1 (defconst context-coloring-benchmark-path
2 (file-name-directory (or load-file-name buffer-file-name)))
3
4 (defun context-coloring-benchmark-resolve-path (path)
5 (expand-file-name path context-coloring-benchmark-path))
6
7 (defun context-coloring-benchmark-log-results (result-file fixture)
8 (elp-results)
9 (let ((results-buffer (current-buffer)))
10 (with-temp-buffer
11 (insert (concat fixture "\n"))
12 (prepend-to-buffer results-buffer (point-min) (point-max)))
13 (with-temp-buffer
14 (insert "\n")
15 (append-to-buffer results-buffer (point-min) (point-max))))
16 (append-to-file nil nil result-file))
17
18 (defun context-coloring-benchmark-js-mode-setup ()
19 (add-hook 'js-mode-hook 'context-coloring-mode)
20 (elp-instrument-package "context-coloring-"))
21
22 (defun context-coloring-benchmark-js-mode-teardown ()
23 (remove-hook 'js-mode-hook 'context-coloring-mode))
24
25 (defun context-coloring-benchmark-js-mode-run ()
26 (context-coloring-benchmark-js-mode-setup)
27 (let ((result-file (context-coloring-benchmark-resolve-path
28 (concat "./results-js-mode-" (format-time-string "%s") ".log"))))
29 (dolist (path '("./fixtures/jquery-2.1.1.js"
30 "./fixtures/lodash-2.4.1.js"
31 "./fixtures/async-0.9.0.js"
32 "./fixtures/mkdirp-0.5.0.js"))
33 (let ((fixture (context-coloring-benchmark-resolve-path path)))
34 ;; Test 5 times.
35 (find-file fixture)
36 (dotimes (n 4)
37 (sit-for 1)
38 (revert-buffer t t))
39 (sit-for 1)
40 (context-coloring-benchmark-log-results result-file fixture))))
41 (context-coloring-benchmark-js-mode-teardown))
42
43 (defun context-coloring-benchmark-js2-mode-setup ()
44 (add-to-list 'load-path (context-coloring-benchmark-resolve-path
45 "../test/fixtures/js2-mode"))
46 (require 'js2-mode)
47 (setq js2-mode-show-parse-errors nil)
48 (setq js2-mode-show-strict-warnings nil)
49 (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
50 (add-hook 'js2-mode-hook 'context-coloring-mode)
51 (elp-instrument-package "context-coloring-"))
52
53 (defun context-coloring-benchmark-js2-mode-teardown ()
54 (remove-hook 'js2-mode-hook 'context-coloring-mode)
55 (setq auto-mode-alist (delete '("\\.js\\'" . js2-mode)
56 auto-mode-alist))
57 (setq js2-mode-show-strict-warnings t)
58 (setq js2-mode-show-parse-errors t)
59 (setq load-path (delete (context-coloring-benchmark-resolve-path
60 "../test/fixtures/js2-mode")
61 load-path)))
62
63 (defun context-coloring-benchmark-js2-mode-run ()
64 (context-coloring-benchmark-js2-mode-setup)
65 (let ((result-file (context-coloring-benchmark-resolve-path
66 (concat "./results-js2-mode-" (format-time-string "%s") ".log"))))
67 (dolist (path '("./fixtures/jquery-2.1.1.js"
68 "./fixtures/lodash-2.4.1.js"
69 "./fixtures/async-0.9.0.js"
70 "./fixtures/mkdirp-0.5.0.js"))
71 (let ((fixture (context-coloring-benchmark-resolve-path path)))
72 ;; Test 5 times.
73 (find-file fixture)
74 (dotimes (n 4)
75 (revert-buffer t t))
76 (context-coloring-benchmark-log-results result-file fixture))))
77 (context-coloring-benchmark-js2-mode-teardown))
78
79 (defun context-coloring-benchmark-run ()
80 ;; (context-coloring-benchmark-js-mode-run)
81 (context-coloring-benchmark-js2-mode-run)
82 (kill-emacs))