From e214510956db134e260407b6ca6a813a1df4a518 Mon Sep 17 00:00:00 2001 From: Nils K Date: Fri, 17 Apr 2020 01:50:16 +0200 Subject: [PATCH] added cache_benchmark --- .gitignore | 3 + cache_benchmark/Makefile | 2 + cache_benchmark/cache.c | 107 +++++++++++++++++++++ cache_benchmark/execute_cache_test.sh | 86 +++++++++++++++++ cache_benchmark/output/cache_test_t420.txt | 80 +++++++++++++++ 5 files changed, 278 insertions(+) create mode 100644 .gitignore create mode 100644 cache_benchmark/Makefile create mode 100644 cache_benchmark/cache.c create mode 100644 cache_benchmark/execute_cache_test.sh create mode 100644 cache_benchmark/output/cache_test_t420.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c76e54 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.exe +*.swp +*.o diff --git a/cache_benchmark/Makefile b/cache_benchmark/Makefile new file mode 100644 index 0000000..4ac94ca --- /dev/null +++ b/cache_benchmark/Makefile @@ -0,0 +1,2 @@ +build: cache.c + gcc cache.c -O2 -o cache.exe diff --git a/cache_benchmark/cache.c b/cache_benchmark/cache.c new file mode 100644 index 0000000..0e41a27 --- /dev/null +++ b/cache_benchmark/cache.c @@ -0,0 +1,107 @@ +#include +#include +#include + +//prints out usage information +void usage(); + +//generate dynamically allocated array, initialized with rand() +int* rand_array(size_t n); + +//converts clock ticks to nano seconds +double clocks_to_ns(double ct); + +//write to /dev/null or nul +//exits if it fails +void int_to_dev_null(int trash); + +//calculates the clock ticks rand() probably needs +//from a hot cache +double clock_ticks_rand(); + +int main(int argc, char* argv[]) { + if(argc != 4) { + usage(); + return 1; + } + unsigned n_bytes; + unsigned array_size; + unsigned n_times_access; + unsigned n_loops; + sscanf(argv[1], "%u", &n_bytes); + sscanf(argv[2], "%u", &n_times_access); + sscanf(argv[3], "%u", &n_loops); + srand(time(NULL)); + array_size = n_bytes / 4; + int* parry = rand_array(array_size); + + clock_t start; + clock_t end; + clock_t overall = 0; + int tmp = 0; + double rc = clock_ticks_rand(); + for(size_t n=0; n array-size n-times-access n-loops\n"); +} +double clock_ticks_rand() { +#define N 1000000 + for(size_t i=0; i filename +# filename shouldn't be a path +# the file will be automatically added to the output folder +if [ $# -ne 1 ] +then + echo "missing output-filename" + exit 1 +fi + +exec >>./output/"$1" +n_times=10000000 +n_count=5 + +echo "#n_times = $n_times" +echo "#n_count = $n_count" +echo "#n_steps = $n_steps" + +step_size_bytes=100 +last_value_bytes=1000 +n_steps=$((last_value_bytes / step_size_bytes)) + +n_bytes=4 +for i in `seq 0 $n_steps` +do + ./cache.exe $n_bytes $n_times $n_count + n_bytes=$((n_bytes + step_size_bytes)) +done + +step_size_bytes=1000 +last_value_bytes=10000 +n_steps=$((last_value_bytes / step_size_bytes)) +n_bytes=4 +for i in `seq 0 $n_steps` +do + ./cache.exe $n_bytes $n_times $n_count + n_bytes=$((n_bytes + step_size_bytes)) +done + +step_size_bytes=10000 +last_value_bytes=100000 +n_steps=$((last_value_bytes / step_size_bytes)) +n_bytes=4 +for i in `seq 0 $n_steps` +do + ./cache.exe $n_bytes $n_times $n_count + n_bytes=$((n_bytes + step_size_bytes)) +done + +step_size_bytes=100000 +last_value_bytes=1000000 +n_steps=$((last_value_bytes / step_size_bytes)) +n_bytes=4 +for i in `seq 0 $n_steps` +do + ./cache.exe $n_bytes $n_times $n_count + n_bytes=$((n_bytes + step_size_bytes)) +done + +step_size_bytes=1000000 +last_value_bytes=10000000 +n_steps=$((last_value_bytes / step_size_bytes)) +n_bytes=4 +for i in `seq 0 $n_steps` +do + ./cache.exe $n_bytes $n_times $n_count + n_bytes=$((n_bytes + step_size_bytes)) +done +step_size_bytes=10000000 +last_value_bytes=100000000 +n_steps=$((last_value_bytes / step_size_bytes)) +n_bytes=4 +for i in `seq 0 $n_steps` +do + ./cache.exe $n_bytes $n_times $n_count + n_bytes=$((n_bytes + step_size_bytes)) +done +step_size_bytes=100000000 +last_value_bytes=1000000000 +n_steps=$((last_value_bytes / step_size_bytes)) +n_bytes=4 +for i in `seq 0 $n_steps` +do + ./cache.exe $n_bytes $n_times $n_count + n_bytes=$((n_bytes + step_size_bytes)) +done diff --git a/cache_benchmark/output/cache_test_t420.txt b/cache_benchmark/output/cache_test_t420.txt new file mode 100644 index 0000000..4efd1c9 --- /dev/null +++ b/cache_benchmark/output/cache_test_t420.txt @@ -0,0 +1,80 @@ +#n_times = 10000000 +#n_count = 5 +#n_steps = +4, 1, 1.796940, 11.427000 +104, 26, 2.900400, 10.326000 +204, 51, 2.884980, 10.322000 +304, 76, 2.013720, 11.318000 +404, 101, 2.281860, 11.109000 +504, 126, 3.361040, 10.419000 +604, 151, 2.853020, 10.410000 +704, 176, 2.825380, 10.880000 +804, 201, 2.450820, 10.867000 +904, 226, 2.844100, 10.433000 +1004, 251, 2.813580, 10.348000 +4, 1, 2.845820, 10.327000 +1004, 251, 2.675060, 10.475000 +2004, 501, 2.823520, 10.341000 +3004, 751, 2.845340, 10.321000 +4004, 1001, 2.540120, 10.626000 +5004, 1251, 2.811960, 10.348000 +6004, 1501, 2.845200, 10.326000 +7004, 1751, 2.842140, 10.322000 +8004, 2001, 2.852820, 10.322000 +9004, 2251, 2.822840, 10.398000 +10004, 2501, 2.827560, 10.334000 +4, 1, 2.666520, 10.492000 +10004, 2501, 2.814660, 10.359000 +20004, 5001, 2.840020, 10.326000 +30004, 7501, 2.450100, 10.714000 +40004, 10001, 2.802600, 10.356000 +50004, 12501, 2.802320, 10.362000 +60004, 15001, 2.824040, 10.339000 +70004, 17501, 2.834120, 10.321000 +80004, 20001, 2.823640, 10.339000 +90004, 22501, 2.840880, 10.322000 +100004, 25001, 2.842940, 10.326000 +4, 1, 2.865800, 10.329000 +100004, 25001, 2.797480, 10.359000 +200004, 50001, 2.825240, 10.342000 +300004, 75001, 2.817100, 10.347000 +400004, 100001, 2.825280, 10.331000 +500004, 125001, 2.900640, 10.350000 +600004, 150001, 2.827060, 10.345000 +700004, 175001, 2.833460, 10.343000 +800004, 200001, 2.812040, 10.346000 +900004, 225001, 2.562740, 10.644000 +1000004, 250001, 2.820360, 10.343000 +4, 1, 2.829680, 10.334000 +1000004, 250001, 2.826580, 10.347000 +2000004, 500001, 6.918360, 10.342000 +3000004, 750001, 12.378520, 10.587000 +4000004, 1000001, 16.424660, 10.293000 +5000004, 1250001, 21.886400, 10.344000 +6000004, 1500001, 22.119560, 10.812000 +7000004, 1750001, 26.157120, 10.286000 +8000004, 2000001, 25.323320, 10.414000 +9000004, 2250001, 27.974520, 10.294000 +10000004, 2500001, 26.809840, 10.320000 +4, 1, 2.501100, 10.660000 +10000004, 2500001, 26.890300, 10.295000 +20000004, 5000001, 31.671960, 10.288000 +30000004, 7500001, 31.187380, 10.286000 +40000004, 10000001, 33.487660, 10.413000 +50000004, 12500001, 31.705220, 10.305000 +60000004, 15000001, 34.792340, 10.288000 +70000004, 17500001, 34.498320, 10.760000 +80000004, 20000001, 32.972400, 10.309000 +90000004, 22500001, 36.819780, 10.300000 +100000004, 25000001, 33.829780, 10.413000 +4, 1, 2.820420, 10.378000 +100000004, 25000001, 36.639460, 10.292000 +200000004, 50000001, 37.877760, 10.387000 +300000004, 75000001, 41.470580, 10.338000 +400000004, 100000001, 42.162180, 10.371000 +500000004, 125000001, 50.617280, 10.766000 +600000004, 150000001, 48.964480, 10.322000 +700000004, 175000001, 55.075340, 10.292000 +800000004, 200000001, 53.195160, 10.285000 +900000004, 225000001, 54.293140, 10.611000 +1000000004, 250000001, 59.733980, 10.345000