Skip to content

Commit

Permalink
updated benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
bisheshank committed Dec 9, 2024
1 parent af1e6b7 commit 9c84240
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
34 changes: 34 additions & 0 deletions benchmarks/bcaryal-benchmark1.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(define (add-n-times x n)
(if (= n 0)
0
(+ x (add-n-times x (sub1 n)))))

(define (find-root x current)
(let ((square (add-n-times current current)))
(if (= square x)
current
(if (< square x)
(find-root x (add1 current))
0))))

(define (sum-sequence x)
(if (= x 0)
0
(+ x (sum-sequence (sub1 x)))))

(define (fib n)
(if (< n 2)
1
(+ (fib (sub1 n))
(fib (- n 2)))))

(define (process x)
(let ((root (find-root x 0)))
(let ((seq (sum-sequence 5)))
(let ((fib-val (fib 5)))
(if (= root 0)
(+ x seq)
(+ (+ x root) (+ seq fib-val)))))))

(let ((x 16))
(print (process x)))
1 change: 1 addition & 0 deletions benchmarks/bcaryal-benchmark1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
43
19 changes: 19 additions & 0 deletions benchmarks/bcaryal-benchmark2.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(define (classify x)
(if (< x 10)
(+ x 1)
(if (< x 20)
(+ x 2)
(+ x 3))))

(define (process x)
(if (= x 0)
0
(+ (classify x)
(classify (sub1 x)))))

(define (chain x)
(+ (process x)
(process (add1 x))))

(let ((x 15))
(print (chain x)))
Empty file.
48 changes: 48 additions & 0 deletions benchmarks/bcaryal-benchmark3.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
(define (constant-fold x)
(+ (+ 1 (+ 2 (+ 3 4)))
(- (+ 5 (+ 6 7))
(+ 8 (+ 9 x)))))

(define (small-func1 x)
(add1 (add1 x)))

(define (small-func2 x)
(sub1 (sub1 x)))

(define (small-func3 x)
(+ (small-func1 x) (small-func2 x)))

(define (complex-compute x y)
(if (< x y)
(+ (constant-fold x)
(small-func3 y))
(+ (small-func3 x)
(constant-fold y))))

(define (repeated-expr x)
(let ((v1 (+ x (+ x (+ x x)))))
(let ((v2 (+ x (+ x (+ x x)))))
(let ((v3 (+ x (+ x (+ x x)))))
(+ v1 (+ v2 v3))))))

(define (chain-calls x)
(small-func1
(small-func2
(small-func3
(small-func1
(small-func2 x))))))

(define (conditional-chain x)
(if (< x 10)
(complex-compute x 20)
(if (< x 20)
(complex-compute x 30)
(complex-compute x 40))))

(do
(let ((base (+ 1 (+ 2 (+ 3 (+ 4 (+ 5 6)))))))
(let ((x (chain-calls base)))
(let ((y (repeated-expr x)))
(let ((z (conditional-chain y)))
(print
(+ z (complex-compute x y))))))))
1 change: 1 addition & 0 deletions benchmarks/bcaryal-benchmark3.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1956

0 comments on commit 9c84240

Please sign in to comment.