]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/context-coloring/benchmark/context-coloring-benchmark.el
Merge remote-tracking branch 'ztree/master'
[gnu-emacs-elpa] / packages / context-coloring / benchmark / context-coloring-benchmark.el
index 004b66fbe13fa3b79b6936da4c8176c3d50f38d6..e020f6faeb8bf4119ac500fc7134daae12e21222 100644 (file)
@@ -1,4 +1,4 @@
-;;; benchmark/context-coloring-benchmark.el --- Benchmarks for context coloring. -*- lexical-binding: t; -*-
+;;; context-coloring-benchmark.el --- Benchmarks for context coloring  -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 2014-2015  Free Software Foundation, Inc.
 
 
 ;; Copyright (C) 2014-2015  Free Software Foundation, Inc.
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+;;; Commentary:
+
+;; Benchmarks for context coloring.
+
+;; Use with `make bench'.
+
 ;;; Code:
 
 ;;; Code:
 
+(require 'context-coloring)
+(require 'js2-mode)
+
+
 (defconst context-coloring-benchmark-path
   (file-name-directory (or load-file-name buffer-file-name))
   "This file's directory.")
 (defconst context-coloring-benchmark-path
   (file-name-directory (or load-file-name buffer-file-name))
   "This file's directory.")
@@ -28,7 +38,7 @@
   (expand-file-name path context-coloring-benchmark-path))
 
 (defun context-coloring-benchmark-log-results (result-file fixture)
   (expand-file-name path context-coloring-benchmark-path))
 
 (defun context-coloring-benchmark-log-results (result-file fixture)
-  "Log benchmarking results for FIXTURE to RESULT-FILE."
+  "Log benchmarking results to RESULT-FILE for fixture FIXTURE."
   (elp-results)
   (let ((results-buffer (current-buffer)))
     (with-temp-buffer
   (elp-results)
   (let ((results-buffer (current-buffer)))
     (with-temp-buffer
@@ -49,7 +59,8 @@ asynchrony."
   "Run the next test in LIST by calling CONTINUE.  When LIST is
 exhausted, call STOP instead."
   (if (null list)
   "Run the next test in LIST by calling CONTINUE.  When LIST is
 exhausted, call STOP instead."
   (if (null list)
-      (context-coloring-benchmark-next-tick stop)
+      (progn
+        (context-coloring-benchmark-next-tick stop))
     (context-coloring-benchmark-next-tick
      (lambda ()
        (funcall
     (context-coloring-benchmark-next-tick
      (lambda ()
        (funcall
@@ -59,8 +70,9 @@ exhausted, call STOP instead."
           (context-coloring-benchmark-next (cdr list) continue stop)))))))
 
 (defun context-coloring-benchmark-async (title setup teardown fixtures callback)
           (context-coloring-benchmark-next (cdr list) continue stop)))))))
 
 (defun context-coloring-benchmark-async (title setup teardown fixtures callback)
-  "Measure the performance of all FIXTURES, calling CALLBACK when
-all are done."
+  "Execute a benchmark titled TITLE with SETUP and TEARDOWN
+callbacks.  Measure the performance of all FIXTURES, calling
+CALLBACK when all are done."
   (funcall setup)
   (let ((result-file (context-coloring-benchmark-resolve-path
                       (format "./logs/results-%s-%s.log"
   (funcall setup)
   (let ((result-file (context-coloring-benchmark-resolve-path
                       (format "./logs/results-%s-%s.log"
@@ -92,7 +104,7 @@ all are done."
          (find-file fixture)))
      (lambda ()
        (funcall teardown)
          (find-file fixture)))
      (lambda ()
        (funcall teardown)
-       (if callback (funcall callback))))))
+       (when callback (funcall callback))))))
 
 (defconst context-coloring-benchmark-js-fixtures
   '("./fixtures/jquery-2.1.1.js"
 
 (defconst context-coloring-benchmark-js-fixtures
   '("./fixtures/jquery-2.1.1.js"
@@ -121,7 +133,6 @@ all are done."
 
 (defun context-coloring-benchmark-js2-mode-setup ()
   "Preparation logic for `js2-mode'."
 
 (defun context-coloring-benchmark-js2-mode-setup ()
   "Preparation logic for `js2-mode'."
-  (require '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))
   (setq js2-mode-show-parse-errors nil)
   (setq js2-mode-show-strict-warnings nil)
   (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))