aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2019-11-13 17:45:09 +0100
committerFlorian Fischer <florian.fl.fischer@fau.de>2019-11-13 17:45:43 +0100
commit91b89ede1923ad2f26d30006928dfadad765ca3f (patch)
tree28b1cd4420e450b01eaf452264df7abc29532b6f
parentf748866e9eb62900485100714bff42647a366af5 (diff)
downloadallocbench-91b89ede1923ad2f26d30006928dfadad765ca3f.tar.gz
allocbench-91b89ede1923ad2f26d30006928dfadad765ca3f.zip
use fixed sizes in loop benchmark and remove legacy source code
-rw-r--r--src/benchmarks/loop/loop.c60
1 files changed, 9 insertions, 51 deletions
diff --git a/src/benchmarks/loop/loop.c b/src/benchmarks/loop/loop.c
index 6297e49..04dcd80 100644
--- a/src/benchmarks/loop/loop.c
+++ b/src/benchmarks/loop/loop.c
@@ -1,44 +1,13 @@
-#include <assert.h>
-#include <malloc.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+int size, iterations;
-static size_t _rand() {
- static __thread size_t seed = 123456789;
- size_t a = 1103515245;
- size_t c = 12345;
- size_t m = 1 << 31;
- seed = (a * seed + c) % m;
- return seed;
-}
-
-typedef struct ThreadArgs {
- double benchmark;
- int allocations;
- int max_size;
-} ThreadArgs;
-
-static void* malloc_then_write(size_t size) {
- void* ptr = malloc(size);
- // Write to ptr
- /* *((char*)ptr) = '!'; */
- return ptr;
-}
-
-static void read_then_free(void* ptr) {
- // Read before free
- /* char s __attribute__((unused)) = *((char*)ptr); */
- free(ptr);
-}
-static void* test_thread_func(void* arg) {
- ThreadArgs* args = (ThreadArgs*)arg;
-
- for(int i = 0; i < args->allocations; i++) {
- void* ptr = malloc_then_write((_rand() % args->max_size) + 1);
- read_then_free(ptr);
+static void* test_thread_func(__attribute__ ((unused)) void* arg) {
+ for(int i = 0; i < iterations; i++) {
+ free(malloc(size));
}
return NULL;
}
@@ -46,21 +15,20 @@ static void* test_thread_func(void* arg) {
int main(int argc, char* argv[]) {
pthread_t* threads;
int num_threads;
- struct ThreadArgs thread_args;
- if (argc < 4) {
- fprintf(stderr, "Usage: %s <num threads> <num allocations> <max size>\n", argv[0]);
+ if (argc != 4) {
+ fprintf(stderr, "Usage: %s <num threads> <iterations> <size>\n", argv[0]);
return 1;
}
num_threads = atoi(argv[1]);
- thread_args.allocations = atoi(argv[2]);
- thread_args.max_size = atoi(argv[3]);
+ iterations = atoi(argv[2]);
+ size = atoi(argv[3]);
threads = (pthread_t*)malloc(num_threads * sizeof(pthread_t));
for (int i = 0; i < num_threads; i++) {
- if (0 != pthread_create(&threads[i], NULL, test_thread_func, &thread_args)) {
+ if (0 != pthread_create(&threads[i], NULL, test_thread_func, NULL)) {
perror("pthread_create");
return 1;
}
@@ -73,15 +41,5 @@ int main(int argc, char* argv[]) {
}
}
- if (argc == 5)
- {
- FILE* f = stdout;
- if (strcmp(argv[4],"stdout") != 0)
- f = fopen(argv[4], "w");
- malloc_info(0, f);
- if (strcmp(argv[4],"stdout") != 0)
- fclose(f);
- }
-
return 0;
}