Skip to content

Commit

Permalink
Make benchmarking script a bit easier to understand
Browse files Browse the repository at this point in the history
  • Loading branch information
davidshepherd7 committed Dec 1, 2024
1 parent bc6af33 commit 0d969bc
Showing 1 changed file with 52 additions and 42 deletions.
94 changes: 52 additions & 42 deletions electric-operator-benchmark.el
Original file line number Diff line number Diff line change
@@ -1,71 +1,57 @@
;; 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 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)


(defun elp-benchmark (repeats &optional setup-fn)
(interactive)

;; (elp-instrument-function #'electric-operator-post-self-insert-function)
;; (elp-instrument-function #'electric-operator-get-rules-for-mode)
;; Instrument all of the interesting functions
(elp-instrument-package "electric-operator")
(elp-instrument-package "electric-operator-")
(elp-instrument-function #'looking-back)
(setq elp-report-limit 50)
(elp-set-master #'electric-operator-longest-matching-rule)

;; 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)
(dolist (_ (-repeat 1000 0))

;; 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))

(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 ()
;; (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")))

;; (elp-benchmark 1000 (lambda ()
;; (c++-mode)
;; (insert "a=")))

;; (elp-benchmark 1000 (lambda ()
;; (c++-mode)
;; (insert "aaorsitenar")))



Expand Down Expand Up @@ -106,3 +92,27 @@
;; (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)

0 comments on commit 0d969bc

Please sign in to comment.