Skip to content

Commit

Permalink
Queue take changed + benchmarks added
Browse files Browse the repository at this point in the history
  • Loading branch information
simo981 committed Apr 20, 2024
1 parent cd2b818 commit 54f8b89
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ DEBUG ?= 0
ifeq ($(DEBUG), 1)
CFLAGS = -g3
else
CFLAGS = -Ofast
CFLAGS = -Ofast -march=native
endif
CC = cc
TARGET = seqperm
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 54f8b89

Please sign in to comment.