-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] refactor benchmark setup (as bench.core ns), add cljs benchmarks,
update cljs dep
- Loading branch information
1 parent
6598437
commit 3d5c313
Showing
4 changed files
with
171 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#+SETUPFILE: ../../src/setup.org | ||
|
||
* Contents :toc_4_gh: | ||
- [[#shared-cljcljs-benchmark-helpers][Shared CLJ/CLJS benchmark helpers]] | ||
- [[#clojure][Clojure]] | ||
- [[#clojurescript][Clojurescript]] | ||
|
||
* Shared CLJ/CLJS benchmark helpers | ||
|
||
** Clojure | ||
|
||
These macros acts as wrappers for perforate's =defgoal= & =defcase= | ||
macros in order to allow for the same syntax of both the CLJ & CLJS | ||
versions of benchmark specs. | ||
|
||
#+BEGIN_SRC clojure :tangle ../babel/benchmarks/thi/ng/geom/bench/core.clj :noweb yes :mkdirp yes :padline no | ||
(ns thi.ng.geom.bench.core | ||
(:require | ||
[perforate.core :as perf])) | ||
|
||
(defmacro defgoal | ||
[goal doc] | ||
`(perf/defgoal ~(symbol (name goal)) ~doc)) | ||
|
||
(defmacro defcase | ||
[goal id args form] | ||
(let [form (last `(list ~@form))] | ||
`(perf/defcase ~(symbol (name goal)) ~id ~args ~form))) | ||
#+END_SRC | ||
|
||
** Clojurescript | ||
|
||
#+BEGIN_SRC clojure :tangle ../babel/benchmarks/thi/ng/geom/bench/core.cljs :noweb yes :mkdirp yes :padline no | ||
(ns thi.ng.geom.bench.core | ||
(:require | ||
[cljs.nodejs :as nodejs])) | ||
|
||
(def Benchmark | ||
(nodejs/require "benchmark")) | ||
|
||
(def goals (atom {})) | ||
|
||
(defn defgoal | ||
[id & _] | ||
(swap! goals assoc id | ||
(.. (.Suite Benchmark) | ||
(on "cycle" (fn [e] (.log js/console (js/String (.-target e))))) | ||
(on "complete" | ||
(fn [e] | ||
(this-as | ||
*this* | ||
(let [fastest (-> *this* | ||
(.filter "fastest") | ||
(.pluck "name") | ||
(aget 0))] | ||
(.log js/console "Fastest is" fastest)))))))) | ||
|
||
(defn defcase | ||
[goal id _ f] | ||
(swap! goals update-in [goal] #(.add % (name id) f))) | ||
|
||
(defn run-goals | ||
[] | ||
(doseq [[id goal] @goals] | ||
(.log js/console "Goal:" (name id)) | ||
(.run goal)) | ||
(.exit js/process)) | ||
#+END_SRC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters