Commit de592221 authored by Florian Fischer's avatar Florian Fischer
Browse files

improve descriptive stats

parent 4e1cf696
Pipeline #66518 failed with stage
in 60 minutes and 1 second
...@@ -10,14 +10,20 @@ LDFLAGS := -luring -pthread -lrt -lm ...@@ -10,14 +10,20 @@ LDFLAGS := -luring -pthread -lrt -lm
CFLAGS := -Werror -Wall -g -O3 CFLAGS := -Werror -Wall -g -O3
# CFLAGS := -Werror -Wall -g -O0 # CFLAGS := -Werror -Wall -g -O0
.PHONY: all clean eval docker-eval check .PHONY: all clean eval eval-stats docker-eval docker-eval-stats check
eval: all eval: all
@for syscall in $(SYSCALLS); do echo -n "$$syscall " ; ./bench-$$syscall $(STATS); done @for syscall in $(SYSCALLS); do ./bench-$$syscall $(STATS); done
eval-stats:
@$(MAKE) STATS=--stats eval
docker-eval: docker-eval:
./docker.sh make eval ./docker.sh make eval
docker-eval-stats:
./docker.sh make eval-stats
all: $(OBJ) all: $(OBJ)
define generateTargets define generateTargets
......
...@@ -49,17 +49,18 @@ int main(int argc, char *argv[]) { ...@@ -49,17 +49,18 @@ int main(int argc, char *argv[]) {
for (int64_t i = 1; i <= exp_iterations; ++i) { for (int64_t i = 1; i <= exp_iterations; ++i) {
do_write(fd, &write_buf, sizeof(write_buf)); do_write(fd, &write_buf, sizeof(write_buf));
nanos[i] = clock_diff_nanos(); nanos[i - 1] = clock_diff_nanos();
cycles[i] = clock_diff_cycles(); cycles[i - 1] = clock_diff_cycles();
} }
if (print_stats) { if (print_stats) {
print_desc_stats("nanos", nanos, exp_iterations); printf("%s:\n", argv[0]);
print_desc_stats("cycles", cycles, exp_iterations); print_desc_stats("nanos", " ", nanos, exp_iterations);
print_desc_stats("cycles", " ", cycles, exp_iterations);
} else { } else {
uint64_t avg_nanos = calc_mean(nanos, exp_iterations); uint64_t avg_nanos = calc_mean(nanos, exp_iterations);
uint64_t avg_cycles = calc_mean(cycles, exp_iterations); uint64_t avg_cycles = calc_mean(cycles, exp_iterations);
printf("avg-nanos: %lu, avg-cycles: %lu\n", avg_nanos, avg_cycles); printf("%s avg-nanos: %lu, avg-cycles: %lu\n", argv[0], avg_nanos, avg_cycles);
} }
free(nanos); free(nanos);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
uint64_t calc_median(uint64_t* data, size_t size) { uint64_t calc_median(const uint64_t* data, size_t size) {
// sample size is odd -> there is a middle value // sample size is odd -> there is a middle value
if (size % 2 == 1) return data[size / 2]; if (size % 2 == 1) return data[size / 2];
...@@ -15,7 +15,12 @@ uint64_t calc_median(uint64_t* data, size_t size) { ...@@ -15,7 +15,12 @@ uint64_t calc_median(uint64_t* data, size_t size) {
return before_median + ((after_median - before_median) / 2); return before_median + ((after_median - before_median) / 2);
} }
uint64_t calc_mean(uint64_t* data, size_t size) { static void check_saple_size(size_t size) {
if (size == 0) errx(EXIT_FAILURE, "data size must not be zero");
}
uint64_t calc_mean(const uint64_t* data, size_t size) {
check_saple_size(size);
uint64_t sum = 0; uint64_t sum = 0;
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
if (__builtin_add_overflow(sum, data[i], &sum)) errx(EXIT_FAILURE, "sum overflowed at %ld", i); if (__builtin_add_overflow(sum, data[i], &sum)) errx(EXIT_FAILURE, "sum overflowed at %ld", i);
...@@ -23,10 +28,11 @@ uint64_t calc_mean(uint64_t* data, size_t size) { ...@@ -23,10 +28,11 @@ uint64_t calc_mean(uint64_t* data, size_t size) {
return sum / size; return sum / size;
} }
uint64_t calc_var(uint64_t* data, size_t size, uint64_t mean) { uint64_t calc_var(const uint64_t* data, size_t size, uint64_t mean) {
check_saple_size(size);
uint64_t sum = 0; uint64_t sum = 0;
for (size_t i = 0; i < size; ++i) { for (size_t i = 0; i < size; ++i) {
const int64_t delta = mean - data[i]; const uint64_t delta = mean - data[i];
const uint64_t delta_pow = (uint64_t)pow((double)delta, 2); const uint64_t delta_pow = (uint64_t)pow((double)delta, 2);
if (__builtin_add_overflow(sum, delta_pow, &sum)) if (__builtin_add_overflow(sum, delta_pow, &sum))
errx(EXIT_FAILURE, "sum overflowed at %ld", i); errx(EXIT_FAILURE, "sum overflowed at %ld", i);
...@@ -44,9 +50,10 @@ static int compare_uint64_t(const void* v1, const void* v2) { ...@@ -44,9 +50,10 @@ static int compare_uint64_t(const void* v1, const void* v2) {
return 0; return 0;
} }
void print_desc_stats(const char* name, uint64_t* data, size_t size) { void print_desc_stats(const char* name, const char* indentation, const uint64_t* data,
size_t size) {
// sort our data // sort our data
qsort(data, size, sizeof(uint64_t), compare_uint64_t); qsort((void*)data, size, sizeof(uint64_t), compare_uint64_t);
const uint64_t min = data[0]; const uint64_t min = data[0];
const uint64_t max = data[size - 1]; const uint64_t max = data[size - 1];
...@@ -55,10 +62,11 @@ void print_desc_stats(const char* name, uint64_t* data, size_t size) { ...@@ -55,10 +62,11 @@ void print_desc_stats(const char* name, uint64_t* data, size_t size) {
const uint64_t var = calc_var(data, size, mean); const uint64_t var = calc_var(data, size, mean);
const uint64_t std = (uint64_t)sqrt((double)var); const uint64_t std = (uint64_t)sqrt((double)var);
printf("%s-min: %lu\n", name, min); printf("%s%s\n", indentation, name);
printf("%s-max: %lu\n", name, max); printf("%s%smin: %lu\n", indentation, indentation, min);
printf("%s-median: %lu\n", name, median); printf("%s%smax: %lu\n", indentation, indentation, max);
printf("%s-mean: %lu\n", name, mean); printf("%s%smedian: %lu\n", indentation, indentation, median);
printf("%s-var: %lu\n", name, var); printf("%s%smean: %lu\n", indentation, indentation, mean);
printf("%s-std: %lu\n", name, std); printf("%s%svar: %lu\n", indentation, indentation, var);
printf("%s%sstd: %lu\n", indentation, indentation, std);
} }
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "stdint.h" #include "stdint.h"
#include "stdlib.h" #include "stdlib.h"
uint64_t calc_mean(uint64_t* data, size_t size); uint64_t calc_mean(const uint64_t* data, size_t size);
uint64_t calc_median(uint64_t* data, size_t size); uint64_t calc_median(const uint64_t* data, size_t size);
uint64_t calc_var(uint64_t* data, size_t size, uint64_t mean); uint64_t calc_var(const uint64_t* data, size_t size, uint64_t mean);
void print_desc_stats(const char* name, uint64_t* data, size_t size); void print_desc_stats(const char* name, const char* indentation, const uint64_t* data, size_t size);
\ No newline at end of file \ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment