Skip to content

Commit

Permalink
test/benchmark: add two tiny benchmark test
Browse files Browse the repository at this point in the history
ack and 1m coroutine test
both fail to run
  • Loading branch information
tiancaiamao committed Nov 29, 2024
1 parent 499505c commit 1567487
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ stringGCFunc(struct GC *gc, void* f) {
struct trieNode gRoot = {};

Obj
makeSymbol(char *s) {
makeSymbol(const char *s) {
char *old = s;
struct trieNode* p = &gRoot;
for(; *s; s++) {
Expand Down
2 changes: 1 addition & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ scmHead *getScmHead(Obj);
void* mustCObj(Obj o);

#define intern(x) makeSymbol(x)
Obj makeSymbol(char *s);
Obj makeSymbol(const char *s);
Obj symbolGet(Obj sym);
char* symbolStr(Obj sym);

Expand Down
7 changes: 7 additions & 0 deletions test/benchmark/ack.cora
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(func ack
0 y => (+ 1 y)
x 0 => (ack (- x 1) 1)
x y => (ack (- x 1) (ack x (- y 1))))

(let n 13
(ack 3 n))
38 changes: 38 additions & 0 deletions test/benchmark/coroutine1m.cora
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
;; create 1M coroutines and check:
;; 1. how much memory it uses
;; 2. how long it takes

(@import "cora/lib/let-loop")
(@import "cora/lib/cml" cml)
(@import "cora/lib/io" io)
(@import "cora/lib/chan" chan)

(let ch (chan.make)
N 1000000
(begin

(defun create ()
(let-loop recur (i 0)
(if (> i N)
(io.display "spawn finish\n")
(begin
(cml.spawn (lambda ()
(let v (cml.perform (chan.recv ch))
(begin
(io.display "receive value")
(io.display v)
(io.display "\n")))))
(recur (+ i 1))))))

(defun boot ()
(let-loop recur1 (i 0)
(if (> i N)
(io.display "test finish\n")
(begin
(cml.perform (chan.send ch i))
(recur1 (+ i 1))))))))

(create)
(io.display "here???\n")
(cml.spawn boot)
(cml.main)

0 comments on commit 1567487

Please sign in to comment.