aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benchmarks/bench_loop.c53
-rw-r--r--loop.py2
2 files changed, 12 insertions, 43 deletions
diff --git a/benchmarks/bench_loop.c b/benchmarks/bench_loop.c
index af7ff10..12d4760 100644
--- a/benchmarks/bench_loop.c
+++ b/benchmarks/bench_loop.c
@@ -15,18 +15,9 @@ static size_t _rand() {
return seed;
}
-/*
-* Available Benchmarks:
-* 1.x: do malloc()/free() in a loop
-* 1: simple loop
-* 1.1: keep num_kept_allocations befor freeing
-* 1.2: keep num_kept_allocations then free all stored
-*/
-
typedef struct ThreadArgs {
double benchmark;
int allocations;
- int num_kept_allocations;
int max_size;
} ThreadArgs;
@@ -44,30 +35,10 @@ static void read_then_free(void* ptr) {
}
static void* test_thread_func(void* arg) {
ThreadArgs* args = (ThreadArgs*)arg;
- void** ptrs = (void**)calloc(args->num_kept_allocations, sizeof(void*));
for(int i = 0; i < args->allocations; i++) {
- int pos = i % args->num_kept_allocations;
-
- if (args->benchmark == 1.1) {
- if (i >= args->num_kept_allocations) {
- read_then_free(ptrs[pos]);
- }
- }
-
- if (args->benchmark == 1.2) {
- if (pos == 0 && ptrs[pos] != NULL) {
- for (int y = 0; y < args->num_kept_allocations; y++) {
- read_then_free(ptrs[y]);
- }
- }
- }
-
- ptrs[pos] = malloc_then_write((_rand() % args->max_size) + 1);
-
- if (args->benchmark == 1.0) {
- read_then_free(ptrs[pos]);
- }
+ void* ptr = malloc_then_write((_rand() % args->max_size) + 1);
+ read_then_free(ptr);
}
return NULL;
}
@@ -77,16 +48,14 @@ int main(int argc, char* argv[]) {
int num_threads;
struct ThreadArgs thread_args;
- if (argc < 6) {
- fprintf(stderr, "Usage: %s <benchmark> <num threads> <num allocations> <max size> <num of stored allocations>\n", argv[0]);
+ if (argc < 4) {
+ fprintf(stderr, "Usage: %s <num threads> <num allocations> <max size>\n", argv[0]);
return 1;
}
- thread_args.benchmark = atof(argv[1]);
- num_threads = atoi(argv[2]);
- thread_args.allocations = atoi(argv[3]);
- thread_args.max_size = atoi(argv[4]);
- thread_args.num_kept_allocations = atoi(argv[5]);
+ num_threads = atoi(argv[1]);
+ thread_args.allocations = atoi(argv[2]);
+ thread_args.max_size = atoi(argv[3]);
threads = (pthread_t*)malloc(num_threads * sizeof(pthread_t));
@@ -104,13 +73,13 @@ int main(int argc, char* argv[]) {
}
}
- if (argc == 7)
+ if (argc == 5)
{
FILE* f = stdout;
- if (strcmp(argv[6],"stdout") != 0)
- f = fopen(argv[6], "w");
+ if (strcmp(argv[4],"stdout") != 0)
+ f = fopen(argv[4], "w");
malloc_info(0, f);
- if (strcmp(argv[6],"stdout") != 0)
+ if (strcmp(argv[4],"stdout") != 0)
fclose(f);
}
diff --git a/loop.py b/loop.py
index 6c75a61..3f7120f 100644
--- a/loop.py
+++ b/loop.py
@@ -9,7 +9,7 @@ class Benchmark_Loop( Benchmark ):
How allocations are freed can be changed with the benchmark
version""",
- self.cmd = "build/bench_loop{binary_suffix} 1.2 {nthreads} 1000000 {maxsize} 10"
+ self.cmd = "build/bench_loop{binary_suffix} {nthreads} 1000000 {maxsize}"
self.args = {
"maxsize" : [2 ** x for x in range(6, 16)],