Skip to content

Commit

Permalink
add dev variants and history for binarytrees and regexme
Browse files Browse the repository at this point in the history
  • Loading branch information
puredanger committed Jan 9, 2014
1 parent 6de9e37 commit 5071158
Show file tree
Hide file tree
Showing 22 changed files with 1,787 additions and 0 deletions.
74 changes: 74 additions & 0 deletions archive/binarytrees.1
@@ -0,0 +1,74 @@
; Copyright (c) Rich Hickey and contributors.
; All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.

; Alioth benchmarks: http://shootout.alioth.debian.org/u64q/benchmark.php?test=binarytrees&lang=all
; Inspired by http://shootout.alioth.debian.org/u64q/program.php?test=binarytrees&lang=java&id=1
; and http://shootout.alioth.debian.org/u64q/program.php?test=binarytrees&lang=clojure&id=5 ;
(ns alioth.binary-trees
(:gen-class))

(set! *warn-on-reflection* true)
(set! *unchecked-math* true)

(def ^:const min-depth 4)

(deftype TreeNode [left right ^int item])

(defn make-tree [^long item ^long depth]
(if (zero? depth)
(TreeNode. nil nil item)
(TreeNode.
(make-tree (dec (* 2 item)) (dec depth))
(make-tree (* 2 item) (dec depth))
item)))

(defn item-check ^long [^TreeNode node]
(if (nil? (.left node))
(.item node)
(+ (+ (.item node)
(item-check (.left node)))
(- (item-check (.right node))))))

(defn iterate-trees [mx mn d]
(let [iterations (bit-shift-left 1 (long (+ mx mn (- d))))]
(format "%d\t trees of depth %d\t check: %d"
(* 2 iterations)
d
(loop [result 0
i 1]
(if (= i (inc iterations))
result
(recur (+ result
(item-check (make-tree i d))
(item-check (make-tree (- i) d)))
(inc i)))))))

(defn main [max-depth]
(let [stretch-depth (inc max-depth)]
(let [tree (make-tree 0 stretch-depth)
check (item-check tree)]
(println (format "stretch tree of depth %d\t check: %d" stretch-depth check)))
(let [agents (repeatedly (.availableProcessors (Runtime/getRuntime)) #(agent []))
long-lived-tree (make-tree 0 max-depth)]
(loop [depth min-depth
[a & more] (cycle agents)
results []]
(if (> depth stretch-depth)
(doseq [r results] (println @r))
(let [result (promise)]
(send a (fn [_]
(deliver result (iterate-trees max-depth min-depth depth))))
(recur (+ 2 depth) more (conj results result)))))
(println (format "long lived tree of depth %d\t check: %d" max-depth (item-check long-lived-tree))))))

(defn -main [& args]
(let [n (if (first args) (Integer/parseInt (first args)) 0)
max-depth (if (> (+ min-depth 2) n) (+ min-depth 2) n)]
(main max-depth)
(shutdown-agents)))
73 changes: 73 additions & 0 deletions archive/binarytrees.10
@@ -0,0 +1,73 @@
; Copyright (c) Rich Hickey and contributors.
; All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.

; Alioth benchmarks: http://shootout.alioth.debian.org/u64q/benchmark.php?test=binarytrees&lang=all
; Inspired by http://shootout.alioth.debian.org/u64q/program.php?test=binarytrees&lang=java&id=1
; and http://shootout.alioth.debian.org/u64q/program.php?test=binarytrees&lang=clojure&id=5 ;
(ns alioth.binary-trees-me
(:gen-class))

(set! *warn-on-reflection* true)
(set! *unchecked-math* true)

(def ^:const ^long min-depth 4)

(deftype TreeNode [left right ^long item])

(defn make-tree [^long item ^long depth]
(if (zero? depth)
(TreeNode. nil nil item)
(let [i2 (* 2 item)
ddec (dec depth)]
(TreeNode. (make-tree (dec i2) ddec) (make-tree i2 ddec) item))))

(defn item-check ^long [^TreeNode node]
(if (nil? (.left node))
(.item node)
(- (+ (.item node)
(item-check (.left node)))
(item-check (.right node)))))

(defn iterate-trees [^long mx ^long mn ^long d]
(let [iterations (bit-shift-left 1 (long (+ mx mn (- d))))]
(format "%d\t trees of depth %d\t check: %d"
(* 2 iterations)
d
(loop [result 0
i 1]
(if (= i (inc iterations))
result
(recur (+ result
(item-check (make-tree i d))
(item-check (make-tree (- i) d)))
(inc i)))))))

(defn main [^long max-depth]
(let [stretch-depth (inc max-depth)]
(let [tree (make-tree 0 stretch-depth)
check (item-check tree)]
(println (format "stretch tree of depth %d\t check: %d" stretch-depth check)))
(let [agents (repeatedly (.availableProcessors (Runtime/getRuntime)) #(agent []))
long-lived-tree (make-tree 0 max-depth)]
(loop [depth min-depth
[a & more] (cycle agents)
results []]
(if (> depth stretch-depth)
(doseq [r results] (println @r))
(let [result (promise)]
(send a (fn [_]
(deliver result (iterate-trees max-depth min-depth depth))))
(recur (+ 2 depth) more (conj results result)))))
(println (format "long lived tree of depth %d\t check: %d" max-depth (item-check long-lived-tree))))))

(defn -main [& args]
(let [n (if (first args) (Long/parseLong (first args)) 0)
max-depth (if (> (+ min-depth 2) n) (+ min-depth 2) n)]
(main max-depth)
(shutdown-agents)))
77 changes: 77 additions & 0 deletions archive/binarytrees.3
@@ -0,0 +1,77 @@
; Copyright (c) Rich Hickey and contributors.
; All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.

; Alioth benchmarks: http://shootout.alioth.debian.org/u64q/benchmark.php?test=binarytrees&lang=all
; Inspired by http://shootout.alioth.debian.org/u64q/program.php?test=binarytrees&lang=java&id=1
; and http://shootout.alioth.debian.org/u64q/program.php?test=binarytrees&lang=clojure&id=5 ;
(ns alioth.binary-trees-me
(:gen-class))

(set! *warn-on-reflection* true)
(set! *unchecked-math* true)

(def ^:const min-depth 4)

(deftype TreeNode [left right ^long item])

(defn make-tree [^long item ^long depth]
(if (zero? depth)
(TreeNode. nil nil item)
(let [item2x (* 2 item)
depth' (unchecked-dec depth)]
(TreeNode.
(make-tree (unchecked-dec item2x) depth')
(make-tree item2x depth')
item))))

(defn item-check ^long [^TreeNode node]
(if (nil? (.left node))
(.item node)
(unchecked-subtract
(unchecked-add (.item node)
(item-check (.left node)))
(item-check (.right node)))))

(defn iterate-trees [mx mn d]
(let [iterations (bit-shift-left 1 (long (+ mx mn (- d))))]
(format "%d\t trees of depth %d\t check: %d"
(* 2 iterations)
d
(loop [result 0
i 1]
(if (= i (inc iterations))
result
(recur (+ result
(item-check (make-tree i d))
(item-check (make-tree (- i) d)))
(inc i)))))))

(defn main [max-depth]
(let [stretch-depth (inc max-depth)]
(let [tree (make-tree 0 stretch-depth)
check (item-check tree)]
(println (format "stretch tree of depth %d\t check: %d" stretch-depth check)))
(let [agents (repeatedly (.availableProcessors (Runtime/getRuntime)) #(agent []))
long-lived-tree (make-tree 0 max-depth)]
(loop [depth min-depth
[a & more] (cycle agents)
results []]
(if (> depth stretch-depth)
(doseq [r results] (println @r))
(let [result (promise)]
(send a (fn [_]
(deliver result (iterate-trees max-depth min-depth depth))))
(recur (+ 2 depth) more (conj results result)))))
(println (format "long lived tree of depth %d\t check: %d" max-depth (item-check long-lived-tree))))))

(defn -main [& args]
(let [n (if (first args) (Integer/parseInt (first args)) 0)
max-depth (if (> (+ min-depth 2) n) (+ min-depth 2) n)]
(main max-depth)
(shutdown-agents)))
74 changes: 74 additions & 0 deletions archive/binarytrees.5
@@ -0,0 +1,74 @@
; Copyright (c) Rich Hickey and contributors.
; All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.

; Alioth benchmarks: http://shootout.alioth.debian.org/u64q/benchmark.php?test=binarytrees&lang=all
; Inspired by http://shootout.alioth.debian.org/u64q/program.php?test=binarytrees&lang=java&id=1
; and http://shootout.alioth.debian.org/u64q/program.php?test=binarytrees&lang=clojure&id=5 ;
(ns alioth.binary-trees-me
(:gen-class))

(set! *warn-on-reflection* true)
(set! *unchecked-math* true)

(def ^:const min-depth 4)

(deftype TreeNode [left right ^long item])

(defn make-tree [^long item ^long depth]
(if (zero? depth)
(TreeNode. nil nil item)
(TreeNode.
(make-tree (dec (* 2 item)) (dec depth))
(make-tree (* 2 item) (dec depth))
item)))

(defn item-check ^long [^TreeNode node]
(if (nil? (.left node))
(.item node)
(- (+ (.item node)
(item-check (.left node)))
(item-check (.right node)))))

(defn iterate-trees [mx mn d]
(let [iterations (bit-shift-left 1 (long (+ mx mn (- d))))]
(format "%d\t trees of depth %d\t check: %d"
(* 2 iterations)
d
(loop [result 0
i 1]
(if (= i (inc iterations))
result
(recur (+ result
(item-check (make-tree i d))
(item-check (make-tree (- i) d)))
(inc i)))))))

(defn main [max-depth]
(let [stretch-depth (inc max-depth)]
(let [tree (make-tree 0 stretch-depth)
check (item-check tree)]
(println (format "stretch tree of depth %d\t check: %d" stretch-depth check)))
(let [agents (repeatedly (.availableProcessors (Runtime/getRuntime)) #(agent []))
long-lived-tree (make-tree 0 max-depth)]
(loop [depth min-depth
[a & more] (cycle agents)
results []]
(if (> depth stretch-depth)
(doseq [r results] (println @r))
(let [result (promise)]
(send a (fn [_]
(deliver result (iterate-trees max-depth min-depth depth))))
(recur (+ 2 depth) more (conj results result)))))
(println (format "long lived tree of depth %d\t check: %d" max-depth (item-check long-lived-tree))))))

(defn -main [& args]
(let [n (if (first args) (Integer/parseInt (first args)) 0)
max-depth (if (> (+ min-depth 2) n) (+ min-depth 2) n)]
(main max-depth)
(shutdown-agents)))
73 changes: 73 additions & 0 deletions archive/binarytrees.7
@@ -0,0 +1,73 @@
; Copyright (c) Rich Hickey and contributors.
; All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.

; Alioth benchmarks: http://shootout.alioth.debian.org/u64q/benchmark.php?test=binarytrees&lang=all
; Inspired by http://shootout.alioth.debian.org/u64q/program.php?test=binarytrees&lang=java&id=1
; and http://shootout.alioth.debian.org/u64q/program.php?test=binarytrees&lang=clojure&id=5 ;
(ns alioth.binary-trees-me
(:gen-class))

(set! *warn-on-reflection* true)
(set! *unchecked-math* true)

(def ^:const min-depth 4)

(deftype TreeNode [left right ^long item])

(defn make-tree [^long item ^long depth]
(if (zero? depth)
(TreeNode. nil nil item)
(let [i2 (* 2 item)
ddec (dec depth)]
(TreeNode. (make-tree (dec i2) ddec) (make-tree i2 ddec) item))))

(defn item-check ^long [^TreeNode node]
(if (nil? (.left node))
(.item node)
(- (+ (.item node)
(item-check (.left node)))
(item-check (.right node)))))

(defn iterate-trees [mx mn d]
(let [iterations (bit-shift-left 1 (long (+ mx mn (- d))))]
(format "%d\t trees of depth %d\t check: %d"
(* 2 iterations)
d
(loop [result 0
i 1]
(if (= i (inc iterations))
result
(recur (+ result
(item-check (make-tree i d))
(item-check (make-tree (- i) d)))
(inc i)))))))

(defn main [max-depth]
(let [stretch-depth (inc max-depth)]
(let [tree (make-tree 0 stretch-depth)
check (item-check tree)]
(println (format "stretch tree of depth %d\t check: %d" stretch-depth check)))
(let [agents (repeatedly (.availableProcessors (Runtime/getRuntime)) #(agent []))
long-lived-tree (make-tree 0 max-depth)]
(loop [depth min-depth
[a & more] (cycle agents)
results []]
(if (> depth stretch-depth)
(doseq [r results] (println @r))
(let [result (promise)]
(send a (fn [_]
(deliver result (iterate-trees max-depth min-depth depth))))
(recur (+ 2 depth) more (conj results result)))))
(println (format "long lived tree of depth %d\t check: %d" max-depth (item-check long-lived-tree))))))

(defn -main [& args]
(let [n (if (first args) (Integer/parseInt (first args)) 0)
max-depth (if (> (+ min-depth 2) n) (+ min-depth 2) n)]
(main max-depth)
(shutdown-agents)))

0 comments on commit 5071158

Please sign in to comment.