v0.24.0 preview

This commit is contained in:
Leonardo Vencovsky committed 2020-06-12 12:34:33 -03:00
1 parent 767fc0d7fd
commit 203516d8cf
7 files changed
+256 -5

No files matched your search

@@ -0,0 +1,46 @@
#ifndef COUNT
#error "Please define COUNT"
#endif
#include "cmc/hashmap.h"
CMC_CMC_HASHMAP_CORE(PUBLIC, HEADER, (hmi32, hashmapi32, , int32_t, int32_t))
CMC_CMC_HASHMAP_CORE(PUBLIC, SOURCE, (hmi32, hashmapi32, , int32_t, int32_t))
int cmp(int32_t a, int32_t b)
{
return (a > b) - (a < b);
}
size_t hash(int32_t a)
{
size_t x = (size_t)a;
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = (x >> 16) ^ x;
return x;
}
struct hashmapi32_fkey *fkey = &(struct hashmapi32_fkey) {
.cmp = cmp,
.hash = hash,
NULL
};
struct hashmapi32_fval *fval = &(struct hashmapi32_fval) {
.cmp = cmp,
.hash = hash,
NULL
};
int main(void)
{
struct hashmapi32 *map = hmi32_new(COUNT, 0.6, fkey, fval);
for (int32_t i = 0; i < COUNT; i++)
hmi32_insert(map, i, i);
hmi32_free(map);
return 0;
}
@@ -0,0 +1,58 @@
import sys
import time
import subprocess
ITERATIONS = 10
VERBOSE = False
NL = '\n'
INCLUDE = "../../../src"
CC = 'gcc'
CCPP = 'g++' # LoL
OPT = '-O3'
COUNT = 2000000
# Common args
args = ['-I', INCLUDE, OPT, f'-DCOUNT={COUNT}', '-DCMC_NO_CALLBACKS']
c_args = [CC, 'hashmap.c', '-o', 'hashmap.exe']
cpp_args = [CCPP, 'unorderedmap.cpp', '-I', INCLUDE, '-o', 'unorderedmap.exe', OPT, f'-DCOUNT={COUNT}']
c_args.extend(args)
cpp_args.extend(args)
subprocess.check_output(c_args)
subprocess.check_output(cpp_args)
total = 0
for i in range(ITERATIONS):
print(f'{i}...', end='')
sys.stdout.flush()
start_time = time.time()
subprocess.call(['./hashmap.exe'])
delta = time.time() - start_time
total += delta
if VERBOSE:
print(f'({delta})')
avg = int(((total / ITERATIONS) * 1e9) / COUNT)
print(f'{"" if VERBOSE else NL}{total / ITERATIONS} seconds for {COUNT} -> AVG[{avg} ns] [hashmap.exe]{NL if VERBOSE else ""}')
total = 0
for i in range(ITERATIONS):
print(f'{i}...', end='')
sys.stdout.flush()
start_time = time.time()
subprocess.call(['./unorderedmap.exe'])
delta = time.time() - start_time
total += delta
if VERBOSE:
print(f'({delta})')
avg = int(((total / ITERATIONS) * 1e9) / COUNT)
print(f'{"" if VERBOSE else NL}{total / ITERATIONS} seconds for {COUNT} -> AVG[{avg} ns] [unorderedmap.exe]{NL if VERBOSE else ""}')
@@ -0,0 +1,16 @@
#ifndef COUNT
#error "Please define COUNT"
#endif
#include <unordered_map>
#include <cstdint>
int main(void)
{
std::unordered_map<int32_t, int32_t> map(COUNT);
for (int32_t i = 0; i < COUNT; i++)
map.insert({i, i});
return 0;
}