diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bfe201..569e5d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,9 @@ jobs: uses: actions/checkout@v4 with: path: 'hw/benchmarks' - ref: ${{ github.event.pull_request.merge_commit_sha }} + ref: ${{ github.event.pull_request.head.sha }} + - name: echo commit + run: echo "sha is ${{ github.event.pull_request.head.sha }}" - name: Run benchmarks working-directory: 'hw/benchmarks' run: chmod -R 1777 ../ && su - cs1260_user -c "cd $(pwd) && eval \$(opam env) && python3 bench.py --repeat 1" diff --git a/benchmarks/benchmark_1.lisp b/benchmarks/benchmark_1.lisp new file mode 100644 index 0000000..84ce469 --- /dev/null +++ b/benchmarks/benchmark_1.lisp @@ -0,0 +1,3 @@ +(define (f x) (- 15 (+ x (+ 8 (- x 2))))) + +(print (let ((x 4)) (f x))) diff --git a/benchmarks/benchmark_2.lisp b/benchmarks/benchmark_2.lisp new file mode 100644 index 0000000..7313529 --- /dev/null +++ b/benchmarks/benchmark_2.lisp @@ -0,0 +1,5 @@ +(define (cube x) + (+ x (+ x x))) + +(do (print (let ((x (read-num))) + (+ (let ((y (+ 3 5))) (cube x)) 1)))) diff --git a/benchmarks/benchmark_3.lisp b/benchmarks/benchmark_3.lisp new file mode 100644 index 0000000..eb09d48 --- /dev/null +++ b/benchmarks/benchmark_3.lisp @@ -0,0 +1 @@ +(print (if (< (+ 9 8) (+ 3 7)) (+ 6 (+ 9 17)) (+ 13 (- 9 2)))) diff --git a/benchmarks/inline-test.lisp b/benchmarks/inline-test.lisp deleted file mode 100644 index d97ba43..0000000 --- a/benchmarks/inline-test.lisp +++ /dev/null @@ -1,67 +0,0 @@ -(define (triple x) (+ x (+ x x))) -(define (increment x) (+ x 1)) -(print - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment - (triple (increment 3))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) diff --git a/benchmarks/lchoi-inline.lisp b/benchmarks/lchoi-inline.lisp new file mode 100644 index 0000000..2a0ea2a --- /dev/null +++ b/benchmarks/lchoi-inline.lisp @@ -0,0 +1,3 @@ +(define (f x) (+ x x)) +(define (g y) (+ (f y) (f y))) +(print (+ (g 2) (g 2))) \ No newline at end of file diff --git a/benchmarks/lchoi-prop.lisp b/benchmarks/lchoi-prop.lisp new file mode 100644 index 0000000..8030657 --- /dev/null +++ b/benchmarks/lchoi-prop.lisp @@ -0,0 +1,4 @@ +(let ((x (- 5 4))) + (let ((y (+ x 4))) + (let ((z (+ x y))) + (print (+ x (+ y z)))))) \ No newline at end of file diff --git a/benchmarks/lchoi-unroll.lisp b/benchmarks/lchoi-unroll.lisp new file mode 100644 index 0000000..ef8e4e3 --- /dev/null +++ b/benchmarks/lchoi-unroll.lisp @@ -0,0 +1,4 @@ +(define (leftshift num bits) + (if (< bits 1) num (+ (leftshift num (- bits 1)) (leftshift num (- bits 1))))) + +(print (leftshift 1 11)) \ No newline at end of file diff --git a/benchmarks/sum_list.lisp b/benchmarks/sum_list.lisp new file mode 100644 index 0000000..392cbe4 --- /dev/null +++ b/benchmarks/sum_list.lisp @@ -0,0 +1,12 @@ +(define (sum lst) + (if (empty? lst) + 0 + (+ (left lst) (sum (right lst))) + ) +) + +(let ((lst (pair 1 (pair 2 (pair 3 (pair 4 ())))))) + (do + (print (sum lst)) + ) +) diff --git a/benchmarks/sum_of_squares.lisp b/benchmarks/sum_of_squares.lisp new file mode 100644 index 0000000..d9f8b6b --- /dev/null +++ b/benchmarks/sum_of_squares.lisp @@ -0,0 +1,21 @@ +(define (square x) + (if (= x 0) + 0 + (+ x (square (- x 1))) + ) +) + +(define (sum-of-squares n) + (if (= n 0) + 0 + (+ (square n) (sum-of-squares (- n 1))) + ) +) + +(do + (print (sum-of-squares 0)) + (newline) + (print (sum-of-squares 5)) + (newline) + (print (sum-of-squares 10)) +) \ No newline at end of file diff --git a/benchmarks/unsorted_list_search.lisp b/benchmarks/unsorted_list_search.lisp new file mode 100644 index 0000000..e3df195 --- /dev/null +++ b/benchmarks/unsorted_list_search.lisp @@ -0,0 +1,23 @@ +(define (search list target) + (if (empty? list) + false + (if (= (left list) target) + 0 + (let ((index (search (right list) target))) + (if index + (+ 1 index) + false ) + ) + ) + ) +) + +(let ((lst (pair 1 (pair 2 (pair 3 (pair 4 ())))))) + (do + (print (search lst 1)) + (newline) + (print (search lst 0)) + (newline) + (print (search lst 4)) + ) +) \ No newline at end of file diff --git a/benchmarks/whulse-both.lisp b/benchmarks/whulse-both.lisp new file mode 100644 index 0000000..b6202d7 --- /dev/null +++ b/benchmarks/whulse-both.lisp @@ -0,0 +1,37 @@ +(define (c0) 0) +(define (c1) 1) +(define (c2) 2) +(define (c3) 3) +(define (c4) 4) +(define (c5) 5) +(define (c6) 6) +(define (c7) 7) +(define (c8) 8) +(define (c9) 9) +(define (c10) 10) + +(define (add-c1-c2) (+ (c1) (c2))) +(define (add-c3-c4) (+ (c3) (c4))) +(define (add-c5-c6) (+ (c5) (c6))) + +(define (sum1) (+ (add-c1-c2) (add-c3-c4))) +(define (sum2) (+ (sum1) (add-c5-c6))) +(define (total-sum) (+ (sum2) (c7))) + +(define (funcA) (+ (c1) (c2))) +(define (funcB) (+ (funcA) (c3))) +(define (funcC) (+ (funcB) (c4))) +(define (funcD) (+ (funcC) (funcA))) +(define (funcE) (+ (funcD) (funcC))) +(define (funcF) (+ (funcE) (funcD))) + +(let ((v1 (funcF))) + (let ((v2 (if (= v1 30) false true))) + (if v2 + (let ((v3 (funcE))) + (let ((v4 (+ v3 v1))) + (let ((v5 (- v4 (c5)))) + (if (= v5 54) + (print v5) + (print 0))))) + (print 0)))) \ No newline at end of file diff --git a/benchmarks/whulse-constant-prop.lisp b/benchmarks/whulse-constant-prop.lisp new file mode 100644 index 0000000..cc7d4be --- /dev/null +++ b/benchmarks/whulse-constant-prop.lisp @@ -0,0 +1,13 @@ +(define (decrement x) + (sub1 x)) + +(define (add y z) + (+ y z)) + +(define (fib n) + (if (< n 2) + n + (add (fib (decrement n)) (fib (decrement (decrement n)))))) + +(let ((result (fib 30))) + (print result)) \ No newline at end of file diff --git a/benchmarks/whulse-inlining.lisp b/benchmarks/whulse-inlining.lisp new file mode 100644 index 0000000..5f2e00c --- /dev/null +++ b/benchmarks/whulse-inlining.lisp @@ -0,0 +1,25 @@ +(define (increment x) + (add1 x)) + +(define (computesum n) + (if (= n 0) + 0 + (+ (increment n) (computesum (sub1 n))))) + +(define (computeaccumulate n) + (if (= n 0) + 0 + (+ (increment n) (computeaccumulate (sub1 n))))) + +(define (computedoublesum n) + (if (= n 0) + 0 + (+ (+ (increment n) (increment n)) (computedoublesum (sub1 n))))) + +(let ((resultsum (computesum 1000))) + (let ((resultaccumulate (computeaccumulate 1000))) + (let ((resultdoublesum (computedoublesum 1000))) + (print (+ resultsum (+ resultaccumulate resultdoublesum))) + ) + ) +) \ No newline at end of file