-
Notifications
You must be signed in to change notification settings - Fork 13
/
electric-operator-benchmark.el
118 lines (80 loc) · 2.93 KB
/
electric-operator-benchmark.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
;; To use this file run: make benchmark
;;
;; Expected result is that electric-operator-post-self-insert-function takes
;; under a second to run 1,000 iterations.
(require 'benchmark)
(require 'elp)
(require 'electric-operator)
(require 'python)
(defun elp-benchmark (repeats &optional setup-fn)
(interactive)
;; Instrument all of the interesting functions
(elp-instrument-package "electric-operator")
(elp-instrument-package "electric-operator-")
(elp-instrument-function #'looking-back)
;; Capture perf data on everything inside the self-insert hook
(elp-set-master #'electric-operator-post-self-insert-function)
;; Prevent garbage collection
(let ((gc-cons-threshold most-positive-fixnum))
(garbage-collect)
;; Run our function a lot
(dolist (_ (-repeat repeats 0))
(with-temp-buffer
(when setup-fn (funcall setup-fn))
(electric-operator-post-self-insert-function))))
(elp-results)
(terpri))
(setq python-indent-guess-indent-offset nil)
(elp-benchmark 1000 (lambda ()
(python-mode)
(insert "a->")))
(elp-benchmark 1000 (lambda ()
(python-mode)
(insert "a=")))
(elp-benchmark 1000 (lambda ()
(c++-mode)
(insert "a=")))
(elp-benchmark 1000 (lambda ()
(c++-mode)
(insert "aaorsitenar")))
;; (defun do-pair ()
;; (electric-operator-mode 1)
;; (let ((with (do-benchmark)))
;; (electric-operator-mode 0)
;; (let ((without (do-benchmark)))
;; (message "with: %S" with)
;; (message "without: %S" without)
;; (message "diffs: %s" (-map (lambda (p) (- (car p) (cdr p))) (-zip with without)))
;; )))
;; (defun do-benchmarks ()
;; (byte-compile-file "electric-operator.el")
;; (load-file "electric-operator.elc")
;; (python-mode)
;; (evil-insert-state)
;; ;; (message "gc off")
;; ;; (electric-operator-mode 1)
;; ;; (let ((gc-cons-threshold most-positive-fixnum))
;; ;; (do-pair))
;; (message "gc on")
;; (do-pair)
;; )
;; (defun do-benchmark ()
;; (garbage-collect)
;; (prog1
;; (benchmark-run-compiled 100 (execute-kbd-macro (kbd "a = b + c * d / e RET")))
;; (delete-region (point-min) (point-max))))
;; (defun other-benchmark ()
;; (interactive)
;; (with-temp-buffer
;; (setq python-indent-guess-indent-offset nil)
;; (python-mode)
;; (let ((gc-cons-threshold most-positive-fixnum))
;; (garbage-collect)
;; (--> (-repeat 20 0)
;; (--map (benchmark-run-compiled 1000 (progn
;; (insert "a=")
;; (electric-operator-post-self-insert-function)
;; (delete-region 1 (point-max)))) it)
;; (--min-by (< (car it) (car other)) it)))))
;; (princ (other-benchmark))
;; (terpri)