[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4b25191 28/79: Refactor benchmarks. Improve benchmark reli
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 4b25191 28/79: Refactor benchmarks. Improve benchmark reliability. |
Date: |
Sun, 14 Jun 2015 00:05:27 +0000 |
branch: master
commit 4b251915a5c0f3f3fd42f99907927e6b2731b45d
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Refactor benchmarks. Improve benchmark reliability.
---
benchmark/context-coloring-benchmark.el | 141 ++++++++++++++++--------------
1 files changed, 75 insertions(+), 66 deletions(-)
diff --git a/benchmark/context-coloring-benchmark.el
b/benchmark/context-coloring-benchmark.el
index e020f6f..19fa4a3 100644
--- a/benchmark/context-coloring-benchmark.el
+++ b/benchmark/context-coloring-benchmark.el
@@ -37,6 +37,44 @@
"Resolve PATH from this file's directory."
(expand-file-name path context-coloring-benchmark-path))
+(defun context-coloring-benchmark-series (sequence callback)
+ "Call each function in SEQUENCE, then call CALLBACK. Each
+function is passed a single callback parameter for it to call
+when it is done."
+ (cond
+ ((null sequence)
+ (funcall callback))
+ (t
+ (funcall
+ (car sequence)
+ (lambda ()
+ (run-with-timer
+ nil nil
+ (lambda ()
+ (context-coloring-benchmark-series
+ (cdr sequence)
+ callback))))))))
+
+(defun context-coloring-benchmark-mapc (sequence iteratee callback)
+ "For each element in SEQUENCE, call ITERATEE, finally call
+CALLBACK. ITERATEE is passed the current element and a callback
+for it to call when it is done."
+ (cond
+ ((null sequence)
+ (funcall callback))
+ (t
+ (funcall
+ iteratee
+ (car sequence)
+ (lambda ()
+ (run-with-timer
+ nil nil
+ (lambda ()
+ (context-coloring-benchmark-mapc
+ (cdr sequence)
+ iteratee
+ callback))))))))
+
(defun context-coloring-benchmark-log-results (result-file fixture)
"Log benchmarking results to RESULT-FILE for fixture FIXTURE."
(elp-results)
@@ -50,36 +88,18 @@
(make-directory (context-coloring-benchmark-resolve-path "./logs") t)
(append-to-file nil nil result-file))
-(defun context-coloring-benchmark-next-tick (function)
- "Defer execution of FUNCTION to clear the stack and to ensure
-asynchrony."
- (run-at-time 0.001 nil function))
-
-(defun context-coloring-benchmark-next (list continue stop)
- "Run the next test in LIST by calling CONTINUE. When LIST is
-exhausted, call STOP instead."
- (if (null list)
- (progn
- (context-coloring-benchmark-next-tick stop))
- (context-coloring-benchmark-next-tick
- (lambda ()
- (funcall
- continue
- (car list)
- (lambda ()
- (context-coloring-benchmark-next (cdr list) continue stop)))))))
-
-(defun context-coloring-benchmark-async (title setup teardown fixtures
callback)
+(defun context-coloring-benchmark (title setup teardown fixtures callback)
"Execute a benchmark titled TITLE with SETUP and TEARDOWN
callbacks. Measure the performance of all FIXTURES, calling
CALLBACK when all are done."
(funcall setup)
+ (elp-instrument-package "context-coloring-")
(let ((result-file (context-coloring-benchmark-resolve-path
(format "./logs/results-%s-%s.log"
title (format-time-string "%s")))))
- (context-coloring-benchmark-next
+ (context-coloring-benchmark-mapc
fixtures
- (lambda (path next)
+ (lambda (path callback)
(let ((fixture (context-coloring-benchmark-resolve-path path))
advice)
(setq
@@ -91,20 +111,21 @@ CALLBACK when all are done."
(lambda ()
(setq count (+ count 1))
;; Test 5 times.
- (if (= count 5)
- (progn
- (advice-remove 'context-coloring-colorize advice)
- (kill-buffer)
- (context-coloring-benchmark-log-results
- result-file
- fixture)
- (funcall next))
- (funcall 'context-coloring-colorize)))))))
+ (cond
+ ((= count 5)
+ (advice-remove 'context-coloring-colorize advice)
+ (kill-buffer)
+ (context-coloring-benchmark-log-results
+ result-file
+ fixture)
+ (funcall callback))
+ (t
+ (funcall 'context-coloring-colorize))))))))
(advice-add 'context-coloring-colorize :around advice)
(find-file fixture)))
(lambda ()
(funcall teardown)
- (when callback (funcall callback))))))
+ (funcall callback)))))
(defconst context-coloring-benchmark-js-fixtures
'("./fixtures/jquery-2.1.1.js"
@@ -113,56 +134,44 @@ CALLBACK when all are done."
"./fixtures/mkdirp-0.5.0.js")
"Arbitrary JavaScript files for performance scrutiny.")
-(defun context-coloring-benchmark-js-mode-setup ()
- "Preparation logic for `js-mode'."
- (add-hook 'js-mode-hook 'context-coloring-mode)
- (elp-instrument-package "context-coloring-"))
-
-(defun context-coloring-benchmark-js-mode-teardown ()
- "Cleanup logic for `js-mode'."
- (remove-hook 'js-mode-hook 'context-coloring-mode))
-
(defun context-coloring-benchmark-js-mode-run (callback)
"Benchmark `js-mode', then call CALLBACK."
- (context-coloring-benchmark-async
+ (context-coloring-benchmark
"js-mode"
- 'context-coloring-benchmark-js-mode-setup
- 'context-coloring-benchmark-js-mode-teardown
+ (lambda ()
+ "Preparation logic for `js-mode'."
+ (add-hook 'js-mode-hook 'context-coloring-mode))
+ (lambda ()
+ "Cleanup logic for `js-mode'."
+ (remove-hook 'js-mode-hook 'context-coloring-mode))
context-coloring-benchmark-js-fixtures
callback))
-(defun context-coloring-benchmark-js2-mode-setup ()
- "Preparation logic for `js2-mode'."
- (setq js2-mode-show-parse-errors nil)
- (setq js2-mode-show-strict-warnings nil)
- (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
- (add-hook 'js2-mode-hook 'context-coloring-mode)
- (elp-instrument-package "context-coloring-"))
-
-(defun context-coloring-benchmark-js2-mode-teardown ()
- "Cleanup logic for `js2-mode'."
- (remove-hook 'js2-mode-hook 'context-coloring-mode)
- (setq auto-mode-alist (delete '("\\.js\\'" . js2-mode)
- auto-mode-alist))
- (setq js2-mode-show-strict-warnings t)
- (setq js2-mode-show-parse-errors t))
-
(defun context-coloring-benchmark-js2-mode-run (callback)
"Benchmark `js2-mode', then call CALLBACK."
- (context-coloring-benchmark-async
+ (context-coloring-benchmark
"js2-mode"
- 'context-coloring-benchmark-js2-mode-setup
- 'context-coloring-benchmark-js2-mode-teardown
+ (lambda ()
+ "Preparation logic for `js2-mode'."
+ (setq js2-mode-show-parse-errors nil)
+ (setq js2-mode-show-strict-warnings nil)
+ (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
+ (add-hook 'js2-mode-hook 'context-coloring-mode))
+ (lambda ()
+ "Cleanup logic for `js2-mode'."
+ (remove-hook 'js2-mode-hook 'context-coloring-mode)
+ (setq auto-mode-alist (delete '("\\.js\\'" . js2-mode)
+ auto-mode-alist))
+ (setq js2-mode-show-strict-warnings t)
+ (setq js2-mode-show-parse-errors t))
context-coloring-benchmark-js-fixtures
callback))
(defun context-coloring-benchmark-run ()
"Benchmark all modes, then exit."
- (context-coloring-benchmark-next
+ (context-coloring-benchmark-series
'(context-coloring-benchmark-js-mode-run
context-coloring-benchmark-js2-mode-run)
- (lambda (function next)
- (funcall function next))
(lambda ()
(kill-emacs))))
- [elpa] master aaf4835 20/79: Remove let-varlist data structure. Cleanup., (continued)
- [elpa] master aaf4835 20/79: Remove let-varlist data structure. Cleanup., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 49265ab 25/79: Simplify comment and string parsing., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 52383b5 26/79: Handle octothorpes., Jackson Ray Hamilton, 2015/06/13
- [elpa] master a283883 24/79: Always colorize the remaining region., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 3d3c693 22/79: Pass interrupt test with recursive colorizer., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 966bd20 31/79: Add test for escape characters., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 7ab01e3 30/79: Fix ignored test., Jackson Ray Hamilton, 2015/06/13
- [elpa] master f88e21c 29/79: Ignore escaped characters., Jackson Ray Hamilton, 2015/06/13
- [elpa] master e06f1a6 27/79: Color comments and strings inside quotes., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 5a8186b 34/79: Color comments and strings inside defuns., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 4b25191 28/79: Refactor benchmarks. Improve benchmark reliability.,
Jackson Ray Hamilton <=
- [elpa] master f3697c0 35/79: Strings are sexps., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 87893df 32/79: Support comma splicing., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 7167e93 19/79: Pass let and let* tests with recursive colorizer., Jackson Ray Hamilton, 2015/06/13
- [elpa] master af4f773 33/79: Colorize comments and strings inside backquotes., Jackson Ray Hamilton, 2015/06/13
- [elpa] master acaaf39 38/79: Add file statistics to benchmarks., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 8836df9 37/79: Add colorization times to logs., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 5661ed0 44/79: Document `:host' and `:port' properties., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 16fa835 40/79: Optimize JSON parser., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 3dfd515 42/79: Messy server implementation., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 872bf5f 46/79: Bump required scopifier version., Jackson Ray Hamilton, 2015/06/13