Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add benchmark commands

  • Loading branch information...
commit 11764b638fea59354655843f6035a054b1f6db01 1 parent f5935f1
@sile authored
Showing with 118 additions and 1 deletion.
  1. +9 −1 Makefile
  2. +62 −0 src/bin/mt-alloc-test.cc
  3. +47 −0 src/bin/mt-malloc-test.cc
View
10 Makefile
@@ -1,4 +1,4 @@
-all: msgque-test allocator-test
+all: msgque-test allocator-test mt-malloc-test mt-alloc-test
allocator-test:
mkdir -p bin
@@ -7,3 +7,11 @@ allocator-test:
msgque-test:
mkdir -p bin
g++ -Iinclude -O2 -o bin/msgque-test src/bin/msgque-test.cc
+
+mt-malloc-test:
+ mkdir -p bin
+ g++ -Iinclude -O2 -o bin/mt-malloc-test src/bin/mt-malloc-test.cc -lpthread
+
+mt-alloc-test:
+ mkdir -p bin
+ g++ -Iinclude -O2 -o bin/mt-alloc-test src/bin/mt-alloc-test.cc -lpthread
View
62 src/bin/mt-alloc-test.cc
@@ -0,0 +1,62 @@
+#include <iostream>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <pthread.h>
+
+#include <imque/allocator.hh>
+#include <imque/shared_memory.hh>
+
+typedef imque::Allocator allocator;
+
+const int CHILD_NUM = 500;
+const int LOOP_COUNT = 1000;
+
+void sigsegv_handler(int sig) {
+ std::cerr << "#" << getpid() << ":" << sig << std::endl;
+ exit(1);
+}
+
+void* child_start(void* data) {
+ allocator& alc = *reinterpret_cast<allocator*>(data);
+ int id = 10;
+
+ std::cout << "# child: " << id << std::endl;
+ srand(time(NULL));
+
+ for(int i=0; i < LOOP_COUNT; i++) {
+ unsigned size = (rand() % 1024) + 1;
+
+ uint32_t idx = alc.allocate(size);
+ memset(alc.ptr<char>(idx), rand()%0x100, size);
+ usleep(rand() % 400);
+ assert(alc.release(idx));
+ }
+ std::cout << "# exit: " << id << std::endl;
+}
+
+int main() {
+ pthread_t children[CHILD_NUM];
+ signal(SIGSEGV, sigsegv_handler);
+
+ imque::SharedMemory mm(1024*CHILD_NUM);
+ if(! mm) {
+ std::cerr << "mmap() failed" << std::endl;
+ return 1;
+ }
+ allocator alc(mm.ptr<void>(), mm.size());
+ alc.init();
+
+ for(int i=0; i < CHILD_NUM; i++) {
+ pthread_create(&children[i], NULL, child_start, reinterpret_cast<void*>(&alc));
+ }
+ for(int i=0; i < CHILD_NUM; i++) {
+ pthread_join(children[i], NULL);
+ }
+
+ return 0;
+}
View
47 src/bin/mt-malloc-test.cc
@@ -0,0 +1,47 @@
+#include <iostream>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <pthread.h>
+
+const int CHILD_NUM = 500;
+const int LOOP_COUNT = 1000;
+
+void sigsegv_handler(int sig) {
+ std::cerr << "#" << getpid() << ":" << sig << std::endl;
+ exit(1);
+}
+
+void* child_start(void* data) {
+ int id = static_cast<int>(reinterpret_cast<long long>(data));
+ std::cout << "# child: " << id << std::endl;
+ srand(time(NULL));
+
+ for(int i=0; i < LOOP_COUNT; i++) {
+ unsigned size = (rand() % 1024) + 1;
+
+ char *buf = new char[size];
+ memset(buf, rand()%0x100, size);
+ usleep(rand() % 400);
+ delete [] buf;
+ }
+ std::cout << "# exit: " << id << std::endl;
+}
+
+int main() {
+ pthread_t children[CHILD_NUM];
+ signal(SIGSEGV, sigsegv_handler);
+
+ for(int i=0; i < CHILD_NUM; i++) {
+ pthread_create(&children[i], NULL, child_start, reinterpret_cast<void*>(i));
+ }
+ for(int i=0; i < CHILD_NUM; i++) {
+ pthread_join(children[i], NULL);
+ }
+
+ return 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.