Skip to content

Commit

Permalink
[core] prepare project for benchmarking, add deps and vector benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 16, 2015
1 parent 4366b08 commit 6598437
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 4 deletions.
161 changes: 161 additions & 0 deletions geom-core/bench/vector.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#+SETUPFILE: ../../src/setup.org

* Contents :toc_4_gh:
- [[#vector-benchmarks][Vector benchmarks]]
- [[#constants][Constants]]
- [[#vec2][Vec2]]
- [[#vec3][Vec3]]
- [[#complete-namespace-definition][Complete namespace definition]]

* Vector benchmarks

** Constants

#+BEGIN_SRC clojure :noweb-ref helpers
(def A2 (vec2 1 2))
(def B2 (vec2 10 20))
(def C2 (vec2 100 200))
(def D2 (vec2 1000 2000))

(def A3 (vec3 1 2 3))
(def B3 (vec3 10 20 30))
(def C3 (vec3 100 200 300))
(def D3 (vec3 1000 2000 3000))

(def N 10.0)
(def M 100.0)
(def O 1000.0)
#+END_SRC

** Vec2

#+BEGIN_SRC clojure :noweb-ref bench
(defgoal vec2-ops "vec2-ops")

(defcase vec2-ops :add-v
[] (g/+ A2 B2))

(defcase vec2-ops :add-vv
[] (g/+ A2 B2 C2))

(defcase vec2-ops :add-n
[] (g/+ A2 N))

(defcase vec2-ops :add-nn
[] (g/+ A2 N M))

(defcase vec2-ops :add-s
[] (g/+ A2 [N M]))

(defcase vec2-ops :scale-v
[] (g/* A2 B2))

(defcase vec2-ops :scale-n
[] (g/* A2 N))

(defcase vec2-ops :madd
[] (g/madd A2 N B2))

(defcase vec2-ops :madd-op2
[] (g/* (g/+ A2 N) B2))

(defcase vec2-ops :dot
[] (g/dot A2 B2))

(defcase vec2-ops :normalize
[] (g/normalize A2))

(defcase vec2-ops :mag
[] (g/mag A2))

(defcase vec2-ops :mag-squared
[] (g/mag-squared A2))

(defcase vec2-ops :mix
[] (g/mix A2 B2 0.5))

(defcase vec2-ops :mix-bi
[] (g/mix A2 B2 C2 D2 0.5 0.5))

(defcase vec2-ops :rotate
[] (g/rotate A2 HALF_PI))
#+END_SRC

** Vec3

#+BEGIN_SRC clojure :noweb-ref bench
(defgoal vec3-ops "vec3-ops")

(defcase vec3-ops :add-v
[] (g/+ A3 B3))

(defcase vec3-ops :add-vv
[] (g/+ A3 B3 C3))

(defcase vec3-ops :add-n
[] (g/+ A3 N))

(defcase vec3-ops :add-nnn
[] (g/+ A3 N M O))

(defcase vec3-ops :add-s
[] (g/+ A3 [N M O]))

(defcase vec3-ops :scale-v
[] (g/* A3 B3))

(defcase vec3-ops :scale-n
[] (g/* A3 N))

(defcase vec3-ops :madd
[] (g/madd A3 N B3))

(defcase vec3-ops :madd-op2
[] (g/* (g/+ A3 N) B3))

(defcase vec3-ops :dot
[] (g/dot A3 B3))

(defcase vec3-ops :cross
[] (g/cross A3 B3))

(defcase vec3-ops :ortho-normal
[] (gu/ortho-normal A3 B3 C3))

(defcase vec3-ops :normalize
[] (g/normalize A3))

(defcase vec3-ops :mag
[] (g/mag A3))

(defcase vec3-ops :mag-squared
[] (g/mag-squared A3))

(defcase vec3-ops :mix
[] (g/mix A3 B3 0.5))

(defcase vec3-ops :mix-bi
[] (g/mix A3 B3 C3 D3 0.5 0.5))

(defcase vec3-ops :rotate-x
[] (g/rotate-x A3 HALF_PI))

(defcase vec3-ops :rotate-axis
[] (g/rotate-around-axis A3 v/V3Y HALF_PI))
#+END_SRC

** Complete namespace definition

#+BEGIN_SRC clojure :tangle ../babel/benchmarks/thi/ng/geom/bench/core/vector.clj :noweb yes :mkdirp yes :padline no
(ns thi.ng.geom.bench.core.vector
(:require
[perforate.core :refer :all]
[thi.ng.geom.core :as g]
[thi.ng.geom.core.utils :as gu]
[thi.ng.geom.core.vector :as v :refer [vec2 vec3]]
[thi.ng.common.math.core :as m :refer [*eps* HALF_PI PI]]))

<<helpers>>

<<bench>>
#+END_SRC
18 changes: 16 additions & 2 deletions geom-core/src/index.org
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ ALPHA quality, in active development.

- [[../test/core.org][thi.ng.geom.core.test.core]]

* Benchmarks

Benchmarks are in the process of being worked and use [[https://github.com/davidsantiago/perforate][lein-perforate]]
(Criterium) and the npm [[https://www.npmjs.com/package/benchmark][benchmark]] package (for CLJS). Results are
available in this spreadsheet:

[[https://docs.google.com/spreadsheets/d/15VBRlZMa0iY2HZEPQ0pFevp3Pzlfi0f2z944LsJD6O8/edit?usp%3Dsharing][Benchmark results]]

* Module definition

** Building & testing this project
Expand Down Expand Up @@ -81,11 +89,17 @@ target/geom-core-<<conf-version()>>.js
:source-paths ["src/cljx"]
:test-paths ["<<conf-gen-test-path>>"]

:perforate {:environments [{:namespaces [thi.ng.geom.bench.core.vector]}]}

:profiles {:dev {:dependencies [<<dep-cljs>>
<<dep-criterium>>]
<<dep-criterium>>
<<dep-perforate>>]
:plugins [<<dep-cljx>>
<<dep-cljsbuild>>
<<dep-cljs-test>>]
<<dep-cljs-test>>
<<dep-perforate>>
<<dep-lein-npm>>]
:node-dependencies [<<dep-npm-benchmark>>]
:global-vars {*warn-on-reflection* true}
:jvm-opts ^:replace []
:auto-clean false
Expand Down
18 changes: 16 additions & 2 deletions src/config.org
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#+NAME: conf-version
#+BEGIN_SRC emacs-lisp
(concat
"0.0-"
"0.0."
(replace-regexp-in-string
"\\`[ \t\n]*" ""
(replace-regexp-in-string
Expand Down Expand Up @@ -87,4 +87,18 @@ target/test-classes
#+BEGIN_SRC clojure
[com.cemerick/clojurescript.test "0.3.3"]
#+END_SRC

**** [[https://github.com/davidsantiago/perforate][perforate]]
#+NAME: dep-perforate
#+BEGIN_SRC clojure
[perforate "0.3.4"]
#+END_SRC
**** [[https://github.com/RyanMcG/lein-npm][lein-npm]]
#+NAME: dep-lein-npm
#+BEGIN_SRC clojure
[lein-npm "0.5.0"]
#+END_SRC
**** [[https://www.npmjs.com/package/benchmark][node benchmark]]
#+NAME: dep-npm-benchmark
#+BEGIN_SRC clojure
[benchmark "1.0.0"]
#+END_SRC

0 comments on commit 6598437

Please sign in to comment.