-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathprettier-benchmarks.el
67 lines (53 loc) · 1.77 KB
/
prettier-benchmarks.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
;;; prettier-benchmarks.el --- Benchmarks for prettier.el -*- lexical-binding: t; -*-
;; Copyright (c) 2022-present Julian Scheid
;;; Commentary:
;; Benchmark suite for prettier.el.
;; Run with: ./makem.sh benchmark
;;; Code:
(require 'prettier)
(setq prettier-el-home (concat
(file-name-directory load-file-name)
"dist/"))
(defun prettier-benchmark ()
"Run all benchmarks."
(prettier-run-benchmark "small-file-no-edits.js")
(prettier-run-benchmark "small-file-many-edits.js")
(prettier-run-benchmark "large-file-no-edits.js")
(prettier-run-benchmark "large-file-many-edits.js"))
(defun prettier-run (file contents)
"Run Prettier on FILE with CONTENTS."
(with-temp-buffer
(insert contents)
(setq buffer-file-name file)
(rename-buffer file)
(set-auto-mode)
(prettier-prettify)
(let* ((error-buffer (get-buffer prettier-error-buffer-name))
(errors (if error-buffer (with-current-buffer error-buffer (buffer-string)) "")))
(unless (equal "" errors)
(error "Errors: %s" errors)))))
(defun prettier-run-benchmark (name)
"Run benchmarks for file named NAME."
(let* ((file (file-truename (concat "benchmark-cases/" name)))
(contents
(with-temp-buffer
(insert-file-contents file)
(buffer-string))))
(dotimes (_ 100) (prettier-run file contents))
(let ((num-runs 100))
(princ
(format
"%s: %dms per run\n"
name
(round
(*
1000.0
(/
(car
(benchmark-run
num-runs
(prettier-run file contents)))
num-runs))))
#'external-debugging-output))))
(provide 'prettier-benchmarks)
;;; prettier-benchmarks.el ends here