-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
1,867 additions
and
1,682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
bin_PROGRAMS = vector map | ||
|
||
vector_SOURCES = \ | ||
vector.c vector_dynamic.c vector_stdlib.cpp \ | ||
vector.h vector_dynamic.h vector_stdlib.h \ | ||
vector.R | ||
vector_CFLAGS = -std=gnu11 -I../src -g -O3 -flto -fuse-linker-plugin | ||
vector_CXXFLAGS = -I../src -g -O3 -flto -fuse-linker-plugin | ||
vector_LDADD = ../libdynamic.la | ||
|
||
map_SOURCES = \ | ||
map.c map_custom.c map_subclass.c map_dynamic.c map_unordered.cpp \ | ||
map.h map_custom.h map_subclass.h map_dynamic.h map_unordered.h \ | ||
map.R | ||
map_CFLAGS = -std=gnu11 -I../src -g -O3 -flto -fuse-linker-plugin | ||
map_CXXFLAGS = -I../src -g -O3 -flto -fuse-linker-plugin | ||
map_LDADD = ../libdynamic.la | ||
|
||
benchmark: vector.pdf map.pdf | ||
|
||
vector.pdf: vector.dat vector.R | ||
./vector.R | ||
|
||
vector.dat: vector | ||
./$^ > $@ | ||
|
||
map.pdf: map.dat map.R | ||
./map.R | ||
|
||
map.dat: map | ||
./$^ > $@ | ||
|
||
CLEANFILES = *.dat *.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
To build the benchmark, invoke | ||
make benchmark | ||
|
||
Which will produce map.pfd and vector.pfd. The benchmark require R, and the ggplot2, scales and sitools libraries. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
library(ggplot2) | ||
library(scales) | ||
library(sitools) | ||
library(gridExtra) | ||
|
||
data.map <- read.csv("map.dat", head=TRUE, sep=",") | ||
|
||
g1 <- ggplot(legend = TRUE) + | ||
labs(list(title = "Insert", x = "Map size", y = "Time/Operation (ns)")) + | ||
theme(plot.title = element_text(size = 10), | ||
axis.title.x = element_text(size = 8), axis.title.y = element_text(size = 8), | ||
axis.text.x = element_text(size = 8), axis.text.y = element_text(size = 8)) + | ||
geom_smooth(method = "loess", span = 0.5, data = data.map, aes(x = size, y = insert, colour = name)) + | ||
scale_y_continuous(labels = comma) + | ||
expand_limits(y = 0) + | ||
scale_x_continuous(trans = log_trans(), breaks = 10^(0:10), labels = comma) | ||
g1$labels$colour <- "Implementation" | ||
|
||
g2 <- ggplot(legend = TRUE) + | ||
labs(list(title = "Lookup", x = "Map size", y = "Time/Operation (ns)")) + | ||
theme(plot.title = element_text(size = 10), | ||
axis.title.x = element_text(size = 8), axis.title.y = element_text(size = 8), | ||
axis.text.x = element_text(size = 8), axis.text.y = element_text(size = 8)) + | ||
geom_smooth(method = "loess", span = 0.5, data = data.map, aes(x = size, y = at, colour = name)) + | ||
scale_y_continuous(labels = comma) + | ||
expand_limits(y = 0) + | ||
scale_x_continuous(trans = log_trans(), breaks = 10^(0:10), labels = comma) | ||
g2$labels$colour <- "Implementation" | ||
|
||
g3 <- ggplot(legend = TRUE) + | ||
labs(list(title = "Delete", x = "Map size", y = "Time/Operation (ns)")) + | ||
theme(plot.title = element_text(size = 10), | ||
axis.title.x = element_text(size = 8), axis.title.y = element_text(size = 8), | ||
axis.text.x = element_text(size = 8), axis.text.y = element_text(size = 8)) + | ||
geom_smooth(method = "loess", span = 0.5, data = data.map, aes(x = size, y = erase, colour = name)) + | ||
scale_y_continuous(labels = comma) + | ||
expand_limits(y = 0) + | ||
scale_x_continuous(trans = log_trans(), breaks = 10^(0:10), labels = comma) | ||
g3$labels$colour <- "Implementation" | ||
|
||
pdf("map.pdf", width = 10, height = 10) | ||
grid.arrange(g1, g2, g3, ncol=1, top = "libdynamic map benchmark") | ||
#dev.off() | ||
|
||
# g4 <- grid.arrangeGrob(g1, g2, g3, ncol=1, top = "libdynamic map benchmark") | ||
#ggsave(g4, file = "map.pdf", width = 10, height = 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
#include <math.h> | ||
#include <time.h> | ||
#include "dynamic.h" | ||
|
||
#include "map.h" | ||
#include "map_custom.h" | ||
#include "map_subclass.h" | ||
#include "map_unordered.h" | ||
#include "map_dynamic.h" | ||
|
||
static map_metric metrics[] = { | ||
{.name = "custom open addressing", .measure = map_custom}, | ||
{.name = "libdynamic", .measure = map_dynamic}, | ||
{.name = "std::map_unordered", .measure = map_unordered}, | ||
{.name = "libdynamic (subclass)", .measure = map_subclass} | ||
}; | ||
|
||
uint64_t ntime(void) | ||
{ | ||
struct timespec ts; | ||
|
||
(void) clock_gettime(CLOCK_MONOTONIC_RAW, &ts); | ||
return ((uint64_t) ts.tv_sec * 1000000000) + ((uint64_t) ts.tv_nsec); | ||
} | ||
|
||
int main() | ||
{ | ||
size_t i, n, n_min = 10, n_max = 1000000; | ||
double k = 1.1; | ||
uint32_t *a; | ||
map_metric *m; | ||
|
||
(void) fprintf(stdout, "name,size,insert,at,erase\n"); | ||
for (n = n_min; n < n_max; n = ceil(k * n)) | ||
{ | ||
a = calloc(n, sizeof *a); | ||
for (i = 0; i < n; i ++) | ||
a[i] = rand(); | ||
|
||
for (m = metrics; m < &metrics[sizeof metrics / sizeof metrics[0]]; m ++) | ||
{ | ||
m->measure(m, a, n); | ||
(void) fprintf(stdout, "%s,%lu,%f,%f,%f\n", m->name, n, m->insert, m->at, m->erase); | ||
} | ||
|
||
free(a); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef BENCHMARKS_MAP_H_INCLUDED | ||
#define BENCHMARKS_MAP_H_INCLUDED | ||
|
||
typedef struct map_metric map_metric; | ||
struct map_metric | ||
{ | ||
char *name; | ||
void (*measure)(map_metric *, uint32_t *, size_t); | ||
double insert; | ||
double at; | ||
double erase; | ||
}; | ||
|
||
uint64_t ntime(void); | ||
|
||
#endif /* BENCHMARKS_MAP_H_INCLUDED */ |
Oops, something went wrong.