Permalink
Browse files

Massive speed boost when the refs related to debugging are dropped.

  • Loading branch information...
1 parent 9151e17 commit 0d4dd1dd6e341f24d78f6138283aa7175eef3cdc @richard-lyman committed Jul 20, 2012
Showing with 13 additions and 9 deletions.
  1. +9 −8 src/com/lithinos/amotoen/core.clj
  2. +4 −1 test/com/lithinos/amotoen/test/core.clj
View
17 src/com/lithinos/amotoen/core.clj
@@ -57,8 +57,8 @@
0
60)
indent-string)))
- (in [t] (dosync (alter indent inc)))
- (de [t] (dosync (alter indent dec)))
+ (in [t] #_(dosync (alter indent inc)))
+ (de [t] #_(dosync (alter indent dec)))
(gp [t] @j)
(sp [t k] (dosync (ref-set j k)))
(clone [t] (gen-ps s @j))
@@ -138,12 +138,12 @@
(defn- try-char [n w]
(if (= n (c w))
- (do
+ ;(do
#_(debug w (str "MATCH: '" (pr-str n) "' with '" (pr-str (c w)) "'"))
- (m w))
- (do
+ (m w);)
+ ;(do
#_(debug w (str "FAIL: '" (pr-str n) "' with '" (pr-str (c w)) "'"))
- nil)))
+ nil));)
(defn- peg-vec [n g w]
(let [p (gp w)]
@@ -186,9 +186,10 @@
(p w "c:" n)
(dosync (ref-set *debug* false)))
+; If the rule and current position pair have already been seen...
(defn pegasus [n g w]
(in w)
- (when (keyword? n) (dosync (ref-set *currentK* n)))
+ #_(when (keyword? n) (dosync (ref-set *currentK* n)))
(let [result (cond
(keyword? n)(do (p w "k:" n)
(when (nil? (n g)) (throw (Error. (str "Keyword '" n "' does not exist in grammar"))))
@@ -200,7 +201,7 @@
(list? n) (do #_(p w "l:" n) (typed-list n g w))
(char? n) (do #_(p w "c:" n) (try-char n w))
true (throw (Error. (str "Unknown type: " n))))]
- (when (keyword? n) (dosync (ref-set *currentK* n)))
+ #_(when (keyword? n) (dosync (ref-set *currentK* n)))
(de w)
result))
View
5 test/com/lithinos/amotoen/test/core.clj
@@ -81,7 +81,10 @@ a")))))
;(println "Single run" (self-check))
;(println "Dump" (time (self-ast)))
;(println "10 runs") (time (doall (take 10 (repeatedly #(self-check)))))
-(println "40 runs") (time (doall (take 40 (repeatedly #(self-check)))))
+(println "100 runs") (time (doall (take 100 (repeatedly #(self-check)))))
+(println "100 runs") (time (doall (take 100 (repeatedly #(self-check)))))
+(println "100 runs") (time (doall (take 100 (repeatedly #(self-check)))))
+(println "100 runs") (time (doall (take 100 (repeatedly #(self-check)))))
;(println "start")
;(let [i (ref 0) j (ref 0)]

0 comments on commit 0d4dd1d

Please sign in to comment.