mirror of
https://github.com/sigmasternchen/libsfuid
synced 2025-03-15 07:59:02 +00:00
added benchmark
This commit is contained in:
parent
18d7e80d42
commit
9822208d98
3 changed files with 32 additions and 2 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -51,5 +51,6 @@ Module.symvers
|
|||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# Executable
|
||||
# Executables
|
||||
F6jigYck4v
|
||||
benchmark
|
||||
|
|
4
Makefile
4
Makefile
|
@ -1,7 +1,9 @@
|
|||
|
||||
|
||||
all: F6jigYck4v
|
||||
|
||||
benchmark: main.c
|
||||
gcc -lm -DBENCHMARK -o $@ $<
|
||||
|
||||
F6jigYck4v: main.c
|
||||
gcc -lm -o $@ $<
|
||||
|
||||
|
|
27
main.c
27
main.c
|
@ -5,6 +5,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
typedef __uint128_t uint128_t;
|
||||
|
||||
|
@ -186,16 +187,42 @@ settings_t getSettings() {
|
|||
}
|
||||
|
||||
void toString(char* string, unsigned long long value, settings_t settings) {
|
||||
#ifdef BENCHMARK
|
||||
struct timespec before, after;
|
||||
clock_gettime(CLOCK_MONOTONIC, &before);
|
||||
#endif
|
||||
|
||||
value = encode(value, settings.prime, settings.max);
|
||||
verbose("encoded: %llu\n", value);
|
||||
convertToString(string, value);
|
||||
|
||||
#ifdef BENCHMARK
|
||||
clock_gettime(CLOCK_MONOTONIC, &after);
|
||||
|
||||
unsigned long long diff = (int64_t)(after.tv_sec - before.tv_sec) * (int64_t) 1000000000UL + (int64_t)(after.tv_nsec - before.tv_nsec);
|
||||
fprintf(stderr, "Time for conversion: %llu ns\n", diff);
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned long long fromString(const char* string, settings_t settings) {
|
||||
#ifdef BENCHMARK
|
||||
struct timespec before, after;
|
||||
clock_gettime(CLOCK_MONOTONIC, &before);
|
||||
#endif
|
||||
|
||||
verbose("test\n");
|
||||
unsigned long long result = convertFromString(string);
|
||||
verbose("encoded: %llu\n", result);
|
||||
result = decode(result, settings.prime, settings.max);
|
||||
|
||||
#ifdef BENCHMARK
|
||||
clock_gettime(CLOCK_MONOTONIC, &after);
|
||||
|
||||
unsigned long long diff = (int64_t)(after.tv_sec - before.tv_sec) * (int64_t) 1000000000UL + (int64_t)(after.tv_nsec - before.tv_nsec);
|
||||
fprintf(stderr, "Time for conversion: %llu ns\n", diff);
|
||||
#endif
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue