Skip to content

Commit d1a2ab0

Browse files
committed
Move with-timing to utils.clj.
1 parent 50cb0a5 commit d1a2ab0

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

src/flatland/useful/state.clj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,6 @@
7171
curr)
7272
@result))))))
7373

74-
(defmacro with-timing
75-
"Same as clojure.core/time but returns a vector of a the result of
76-
the code and the milliseconds rather than printing a string. Runs
77-
the code in an implicit do."
78-
[& body]
79-
`(let [start# (System/nanoTime)
80-
ret# ~(cons 'do body)]
81-
[ret# (/ (double (- (System/nanoTime) start#)) 1000000.0)]))
82-
8374
(let [executor (ScheduledThreadPoolExecutor. 1 (reify ThreadFactory
8475
(newThread [this r]
8576
(doto (Thread. r)

src/flatland/useful/utils.clj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,13 @@
262262
~@(mapcat (fn [[val form]]
263263
[(fix val, list? set, hash-set) form])
264264
(partition 2 clauses))
265-
~default)))
265+
~default)))
266+
267+
(defmacro with-timing
268+
"Same as clojure.core/time but returns a vector of a the result of
269+
the code and the milliseconds rather than printing a string. Runs
270+
the code in an implicit do."
271+
[& body]
272+
`(let [start# (System/nanoTime)
273+
ret# ~(cons 'do body)]
274+
[ret# (/ (double (- (System/nanoTime) start#)) 1000000.0)]))

test/flatland/useful/state_test.clj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@
3131
(swap! a inc))]
3232
(is (odd? (wait-until a odd?))))))
3333

34-
(deftest test-with-timing
35-
(let [[ret ms] (with-timing
36-
(+ 2 2)
37-
(+ 3 3))]
38-
(is (= ret 6))
39-
(is (float? ms))))
40-
41-
42-
4334
(def ^{:dynamic true} *value* 1)
4435

4536
(deftest test-alter-var

test/flatland/useful/utils_test.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,10 @@
190190
(is (= :b (switch 3, #{1} :a, (2 3) :b, inc :c, :d)))
191191
(is (= :c (switch inc, #{1} :a, (2 3) :b, inc :c, :d)))
192192
(is (= :d (switch :foo, #{1} :a, (2 3) :b, inc :c, :d)))))
193+
194+
(deftest test-with-timing
195+
(let [[ret ms] (with-timing
196+
(+ 2 2)
197+
(+ 3 3))]
198+
(is (= ret 6))
199+
(is (float? ms))))

0 commit comments

Comments
 (0)