diff --git a/README.md b/README.md index a393d1c..5498470 100644 --- a/README.md +++ b/README.md @@ -84,4 +84,18 @@ We want to generate 1M strings of length 12 with our own charset We want to generate 1M strings of length 12 with default charset ascii ``` ./seqperm --random 1000000,12 --charset ascii +``` +## Benchmarks (vs itertools) +### Apple M1 with N_THREADS = 8 +Refer to total value for real execution time + +Trying to generate all permutations from length 1 to length 11 of `a b c d e f g h i l m` +``` +seqperm 30,06s user 60,88s system 26,947 total +itertools 72,94s user 0,06s system 1:13,10 total +``` +Trying to generate all permutations from length 1 to length 8 of `a b c d e f g h i l m n o p q` +``` +seqperm 91,48s user 219,63s system 1:21,62 total +itertools 169,68s user 0,13s system 2:50,11 total ``` \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index 4890861..b6b20c0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,7 @@ DEBUG ?= 0 ifeq ($(DEBUG), 1) CFLAGS = -g3 else - CFLAGS = -Ofast + CFLAGS = -Ofast -march=native endif CC = cc TARGET = seqperm diff --git a/src/main.c b/src/main.c index dd9d47e..817e50d 100644 --- a/src/main.c +++ b/src/main.c @@ -552,6 +552,7 @@ int main(int argc, char **argv) } gen_bin_perms(bin, word_size, 0, max_len, 0, min_len); FREE_P(bin); + global_queue->head = global_queue->tail - 1; pthread_t tworker[N_THREAD]; memset(&tworker, 0x0, sizeof(tworker)); size_t pos = 0; diff --git a/src/queue.c b/src/queue.c index 5b386d3..f0b7d92 100644 --- a/src/queue.c +++ b/src/queue.c @@ -37,8 +37,8 @@ void push_queue(Queue_t *Q, char **aux, size_t len) input_t *pop_queue(Queue_t *Q) { input_t *aux = NULL; - unsigned int idx = atomic_fetch_add(&Q->head, 1); - aux = idx < Q->maxsize ? Q->words[idx] : NULL; + long idx = atomic_fetch_sub(&Q->head, 1); + aux = idx >= 0 ? Q->words[idx] : NULL; return aux; } diff --git a/src/queue.h b/src/queue.h index fe20173..c3056f1 100644 --- a/src/queue.h +++ b/src/queue.h @@ -29,7 +29,7 @@ typedef struct input_aux_perm typedef struct Queue { input_t **words; - atomic_uint head; + atomic_long head; size_t tail; size_t maxsize; } Queue_t;