ref: 3df92bd8dd256de9b90fd12a4d63d8bf458f1b83
parent: 6de29815680c706b227997cd27ea4fa1ae6e6540
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jan 14 21:58:08 EST 2024
bench: add pingpong
--- a/test.c
+++ b/test.c
@@ -141,6 +141,38 @@
}
}
+void
+pingpongbench(B *b)
+{
+ int i;
+ int pfd[2];
+ char buf[32];
+
+ if(pipe(pfd) == -1)
+ sysfatal("pipe: %r");
+ switch(fork()){
+ case -1:
+ sysfatal("fork: %r");
+ break;
+ case 0:
+ while(1){
+ if(read(pfd[0], buf, sizeof(buf)) != 4)
+ sysfatal("wrk: read: %r");
+ if(write(pfd[1], "pong", 4) != 4)
+ sysfatal("wrk: write: %r");
+ }
+ break;
+ default:
+ for(i = 0; i < b->N; i++){
+ if(write(pfd[1], "ping", 4) != 4)
+ sysfatal("write: %r");
+ if(read(pfd[0], buf, sizeof(buf)) != 4)
+ sysfatal("read: %r");
+ }
+ break;
+ }
+}
+
Lock l;
QLock q;
SLock s;
@@ -199,16 +231,22 @@
free(wait());
}
-#define LKB(nthr) \
- void benchlock##nthr(B *b){lockbench(hammerlock, nthr, b->N);} \
- void benchqlock##nthr(B *b){lockbench(hammerqlock, nthr, b->N);} \
- void benchslock##nthr(B *b){lockbench(hammerslock, nthr, b->N);}
+void benchlock1(B *b){lockbench(hammerlock, 1, b->N);}
+void benchqlock1(B *b){lockbench(hammerqlock, 1, b->N);}
+void benchslock1(B *b){lockbench(hammerslock, 1, b->N);}
+void benchlock4(B *b){lockbench(hammerlock, 4, b->N);}
+void benchqlock4(B *b){lockbench(hammerqlock, 4, b->N);}
+void benchslock4(B *b){lockbench(hammerslock, 4, b->N);}
+void benchlock16(B *b){lockbench(hammerlock, 16, b->N);}
+void benchqlock16(B *b){lockbench(hammerqlock, 16, b->N);}
+void benchslock16(B *b){lockbench(hammerslock, 16, b->N);}
+void benchlock64(B *b){lockbench(hammerlock, 64, b->N);}
+void benchqlock64(B *b){lockbench(hammerqlock, 64, b->N);}
+void benchslock64(B *b){lockbench(hammerslock, 64, b->N);}
+void benchlock512(B *b){lockbench(hammerlock, 512, b->N);}
+void benchqlock512(B *b){lockbench(hammerqlock, 512, b->N);}
+void benchslock512(B *b){lockbench(hammerslock, 512, b->N);}
-LKB(1)
-LKB(4)
-LKB(32)
-LKB(512)
-
void
main(void)
{
@@ -233,13 +271,19 @@
bench("qlock4", benchqlock4);
bench("slock4", benchslock4);
- bench("lock32", benchlock32);
- bench("qlock32", benchqlock32);
- bench("slock32", benchslock32);
+ bench("lock16", benchlock16);
+ bench("qlock16", benchqlock16);
+ bench("slock16", benchslock16);
+ bench("lock64", benchlock64);
+ bench("qlock64", benchqlock64);
+ bench("slock64", benchslock64);
+
bench("lock512", benchlock512);
bench("qlock512", benchqlock512);
bench("slock512", benchslock512);
+
+ bench("pingpong", pingpongbench);
exits(0);
}