summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--benchmarks/plot.py24
-rw-r--r--benchmarks/run_all.bat6
-rw-r--r--benchmarks/run_clang.sh11
-rw-r--r--benchmarks/run_gcc.sh11
-rw-r--r--benchmarks/run_vc.bat12
-rw-r--r--benchmarks/vector_vs_deque.cpp355
6 files changed, 43 insertions, 376 deletions
diff --git a/benchmarks/plot.py b/benchmarks/plot.py
index 228209e2..add0fc3f 100644
--- a/benchmarks/plot.py
+++ b/benchmarks/plot.py
@@ -1,24 +1,11 @@
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
-#sns.set_theme(style="whitegrid")
-
-
-# Initialize the matplotlib figure
-#f, ax = plt.subplots(figsize=(6, 15))
-
-# Load the example car crash dataset
-#crashes = sns.load_dataset("car_crashes").sort_values("total", ascending=False)
-
-df = pd.read_csv('all.csv')
-#column_list = ['insert','erase','find','iter','destruct']
-#df['sum'] = df[column_list].sum(axis=1)
-#df = df.sort_values('sum', ascending=False)
-
-#sns.set_color_codes("pastel")
-#g1 = sns.barplot(x='Method', y='Ratio', data=df, hue='Library', ci=68)
+sns.set_theme(style="whitegrid")
+df = pd.read_csv('plot_perf.csv')
df = df[df.Method != 'total']
+
g = sns.catplot(data=df, x='Method', y='Seconds', hue='Library', col='C', kind='bar',
ci=68, legend=False, col_wrap=2, sharex=False, aspect=1.6, height=3)
g.set_xlabels('')
@@ -28,9 +15,4 @@ g.add_legend(bbox_to_anchor=(0.75, 0.2), borderaxespad=0.)
g.fig.subplots_adjust(top=0.90, left=0.06, bottom=0.07)
g.fig.suptitle('Benchmark STC vs c++ std containers', fontsize=15, y=0.98)
-#a1 = g.fig.axes[1]
-#a1.set_title("Custom Title")
-
-#g.despine(right=True)
-#sns.despine(left=True, bottom=True)
plt.show()
diff --git a/benchmarks/run_all.bat b/benchmarks/run_all.bat
new file mode 100644
index 00000000..25f7af83
--- /dev/null
+++ b/benchmarks/run_all.bat
@@ -0,0 +1,6 @@
+set out=plot_perf.csv
+echo Compiler,Library,C,Method,Seconds,Ratio> %out%
+sh run_gcc.sh >> %out%
+sh run_clang.sh >> %out%
+rem make sure cl.exe environment is available.
+call run_vc.bat >> %out%
diff --git a/benchmarks/run_clang.sh b/benchmarks/run_clang.sh
new file mode 100644
index 00000000..71a8981d
--- /dev/null
+++ b/benchmarks/run_clang.sh
@@ -0,0 +1,11 @@
+clang++ -I.. -O3 -o cdeq_benchmark.exe cdeq_benchmark.cpp
+clang++ -I.. -O3 -o clist_benchmark.exe clist_benchmark.cpp
+clang++ -I.. -O3 -o cmap_benchmark.exe cmap_benchmark.cpp
+clang++ -I.. -O3 -o csmap_benchmark.exe csmap_benchmark.cpp
+clang++ -I.. -O3 -o cvec_benchmark.exe cvec_benchmark.cpp
+
+./cdeq_benchmark.exe Win-Clang-11
+./clist_benchmark.exe Win-Clang-11
+./cmap_benchmark.exe Win-Clang-11
+./csmap_benchmark.exe Win-Clang-11
+./cvec_benchmark.exe Win-Clang-11
diff --git a/benchmarks/run_gcc.sh b/benchmarks/run_gcc.sh
new file mode 100644
index 00000000..5c25b662
--- /dev/null
+++ b/benchmarks/run_gcc.sh
@@ -0,0 +1,11 @@
+g++ -I.. -O3 -o cdeq_benchmark.exe cdeq_benchmark.cpp
+g++ -I.. -O3 -o clist_benchmark.exe clist_benchmark.cpp
+g++ -I.. -O3 -o cmap_benchmark.exe cmap_benchmark.cpp
+g++ -I.. -O3 -o csmap_benchmark.exe csmap_benchmark.cpp
+g++ -I.. -O3 -o cvec_benchmark.exe cvec_benchmark.cpp
+
+./cdeq_benchmark.exe Mingw-g++-9.20
+./clist_benchmark.exe Mingw-g++-9.20
+./cmap_benchmark.exe Mingw-g++-9.20
+./csmap_benchmark.exe Mingw-g++-9.20
+./cvec_benchmark.exe Mingw-g++-9.20 \ No newline at end of file
diff --git a/benchmarks/run_vc.bat b/benchmarks/run_vc.bat
new file mode 100644
index 00000000..848f6924
--- /dev/null
+++ b/benchmarks/run_vc.bat
@@ -0,0 +1,12 @@
+cl.exe -nologo -EHsc -std:c++latest -I.. -O2 cdeq_benchmark.cpp >nul
+cl.exe -nologo -EHsc -std:c++latest -I.. -O2 clist_benchmark.cpp >nul
+cl.exe -nologo -EHsc -std:c++latest -I.. -O2 cmap_benchmark.cpp >nul
+cl.exe -nologo -EHsc -std:c++latest -I.. -O2 csmap_benchmark.cpp >nul
+cl.exe -nologo -EHsc -std:c++latest -I.. -O2 cvec_benchmark.cpp >nul
+del *.obj >nul
+
+cdeq_benchmark.exe VC-19.28
+clist_benchmark.exe VC-19.28
+cmap_benchmark.exe VC-19.28
+csmap_benchmark.exe VC-19.28
+cvec_benchmark.exe VC-19.28 \ No newline at end of file
diff --git a/benchmarks/vector_vs_deque.cpp b/benchmarks/vector_vs_deque.cpp
deleted file mode 100644
index 46da98b7..00000000
--- a/benchmarks/vector_vs_deque.cpp
+++ /dev/null
@@ -1,355 +0,0 @@
-
-#include <deque>
-#include <vector>
-#include <algorithm>
-#include <iostream>
-#include <ctime>
-#include <stc/cmap.h>
-#include <stc/cvec.h>
-#include <stc/cdeq.h>
-#include <stc/cstr.h>
-#include <stc/crandom.h>
-
-typedef struct {const char* first; int second;} Si;
-using_cvec(si, Si, c_no_compare);
-cvec_si tm = cvec_si_init();
-
-void add(cvec_si* tm, const char* s, int n) { Si si = {s, n}; cvec_si_push_back(tm, si); }
-
-
-void test_vector(const int num_iterations)
-{
- std::vector<int> v;
- stc64_t rng = stc64_init(0);
- v.reserve(num_iterations + 2); //Ensure there is enough space reserved.
-
- // == PUSH_BACK
- {
- clock_t t1 = std::clock();
-
- for (int i=0; i<(num_iterations>>1); ++i)
- {
- v.push_back(stc64_rand(&rng));
- }
-
- clock_t t2 = std::clock();
- add(&tm, "vector::push_back", t2 - t1);
- printf("#");
- }
-
- // == INSERT FRONT
- {
- clock_t t1 = std::clock();
-
- for (int i=0; i<(num_iterations>>1); ++i)
- {
- // Rather add some more elements to back.
- v.push_back(stc64_rand(&rng));
- }
-
- clock_t t2 = std::clock();
- add(&tm, "vector::push_back", t2 - t1);
- printf("#");
- }
-
- // == SORT
- {/*
- clock_t t1 = std::clock();
-
- std::sort(v.begin(), v.end());
-
- clock_t t2 = std::clock();
- add(&tm, "vector::sort", t2 - t1);
- printf("#");*/
- }
-
- // == ITERATE
- {
- clock_t t1 = std::clock();
-
- for (int i=0; i<num_iterations; ++i)
- {
- v[i] = 2;
- }
-
- clock_t t2 = std::clock();
- add(&tm, "vector::iterate", t2 - t1);
- printf("#");
- }
-
- // == POP BACK
- {
- clock_t t1 = std::clock();
- volatile int number_sink = 0;
-
- for (int i=0; i<(num_iterations>>1); ++i)
- {
- number_sink += v.back();
- v.pop_back();
- }
- clock_t t2 = std::clock();
- add(&tm, "vector::pop_back", t2 - t1);
- printf("#");
- }
-}
-
-void test_deque(const int num_iterations)
-{
- std::deque<int> d;
- stc64_t rng = stc64_init(0);
-
- // == PUSH_BACK
- {
- clock_t t1 = std::clock();
-
- for (int i=0; i<(num_iterations>>1); ++i)
- {
- d.push_back(stc64_rand(&rng));
- }
-
- clock_t t2 = std::clock();
- add(&tm, "deque::push_back", t2 - t1);
- printf("#");
- }
-
- // == INSERT FRONT
- {
- clock_t t1 = std::clock();
-
- for (int i=0; i<(num_iterations>>1); ++i)
- {
- d.push_front(stc64_rand(&rng));
- }
-
- clock_t t2 = std::clock();
- add(&tm, "deque::push_front", t2 - t1);
- printf("#");
- }
-
- // == SORT
- {/*
- clock_t t1 = std::clock();
-
- std::sort(d.begin(), d.end());
-
- clock_t t2 = std::clock();
- add(&tm, "deque::sort", t2 - t1);
- printf("#");*/
- }
-
- // == ITERATE
- {
- clock_t t1 = std::clock();
-
- for (int i=0; i<num_iterations; ++i)
- {
- d[i] = 2;
- }
-
- clock_t t2 = std::clock();
- add(&tm, "deque::iterate", t2 - t1);
- printf("#");
- }
-
- // == POP BACK
- {
- clock_t t1 = std::clock();
- volatile int number_sink = 0;
-
- for (int i=0; i<(num_iterations>>1); ++i)
- {
- number_sink += d.back();
- d.pop_back();
- }
-
- clock_t t2 = std::clock();
- add(&tm, "deque::pop_back", t2 - t1);
- printf("#");
- }
-}
-
-
-
-
-using_cvec(i, int);
-
-
-void test_cvec(const int num_iterations)
-{
- cvec_i v = cvec_i_init();
- stc64_t rng = stc64_init(0);
- //v.reserve(num_iterations + 2); //Ensure there is enough space reserved.
-
- // == PUSH_BACK
- {
- clock_t t1 = std::clock();
-
- for (int i=0; i<(num_iterations>>1); ++i)
- {
- cvec_i_push_back(&v, stc64_rand(&rng));
- }
-
- clock_t t2 = std::clock();
- add(&tm, "cvec_push_back", t2 - t1);
- printf("#");
- }
-
- // == INSERT FRONT
- {
- clock_t t1 = std::clock();
-
- for (int i=0; i<(num_iterations>>1); ++i)
- {
- // Rather add some more elements to back.
- cvec_i_push_back(&v, stc64_rand(&rng));
- }
-
- clock_t t2 = std::clock();
- add(&tm, "cvec_push_front", t2 - t1);
- printf("#");
- }
-
- // == SORT
- {/*
- clock_t t1 = std::clock();
-
- cvec_i_sort(&v);
-
- clock_t t2 = std::clock();
- add(&tm, "cvec_sort", t2 - t1);
- printf("#");*/
- }
-
- // == ITERATE
- {
- clock_t t1 = std::clock();
-
- for (int i=0; i<num_iterations; ++i)
- {
- v.data[i] = 2;
- }
-
- clock_t t2 = std::clock();
- add(&tm, "cvec_iterate", t2 - t1);
- printf("#");
- }
-
- // == POP BACK
- {
- clock_t t1 = std::clock();
- volatile int number_sink = 0;
-
- for (int i=0; i<(num_iterations>>1); ++i)
- {
- number_sink += *cvec_i_back(&v);
- cvec_i_pop_back(&v);
- }
- clock_t t2 = std::clock();
- add(&tm, "cvec_pop_back", t2 - t1);
- printf("#");
- }
- cvec_i_del(&v);
-}
-
-
-using_cdeq(i, int);
-
-void test_cdeq(const int num_iterations)
-{
- cdeq_i d = cdeq_i_with_capacity(num_iterations + 2);
- stc64_t rng = stc64_init(0);
-
- // == PUSH_BACK
- {
- clock_t t1 = std::clock();
-
- for (int i=0; i<(num_iterations>>1); ++i)
- {
- cdeq_i_push_back(&d, stc64_rand(&rng));
- }
-
- clock_t t2 = std::clock();
- add(&tm, "cdeq_push_back", t2 - t1);
- printf("#");
- }
-
- // == INSERT FRONT
- {
- clock_t t1 = std::clock();
-
- for (int i=0; i<(num_iterations>>1); ++i)
- {
- cdeq_i_push_front(&d, stc64_rand(&rng));
- }
-
- clock_t t2 = std::clock();
- add(&tm, "cdeq_push_front", t2 - t1);
- printf("#");
- }
-
- // == SORT
- {/*
- clock_t t1 = std::clock();
-
- std::sort(d.begin(), d.end());
-
- clock_t t2 = std::clock();
- add(&tm, "deque_sort", t2 - t1);
- printf("#");*/
- }
-
- // == ITERATE
- {
- clock_t t1 = std::clock();
-
- for (int i=0; i<num_iterations; ++i)
- {
- d.data[i] = 2;
- }
-
- clock_t t2 = std::clock();
- add(&tm, "cdeq_iterate", t2 - t1);
- printf("#");
- }
-
- // == POP BACK
- {
- clock_t t1 = std::clock();
- volatile int number_sink = 0;
-
- for (int i=0; i<(num_iterations>>1); ++i)
- {
- number_sink += *cdeq_i_back(&d);
- cdeq_i_pop_back(&d);
- }
-
- clock_t t2 = std::clock();
- add(&tm, "cdeq_pop_back", t2 - t1);
- printf("#");
- }
- cdeq_i_del(&d);
-}
-
-
-
-int main(void)
-{
- int num_iterations = 500000000; // 100M elements * 4 bytes.
- num_iterations = (num_iterations >> 1) << 1; // Make sure num_iterations is even.
-
- std::cout << "Doing tests..." << std::endl;
-
- test_vector(num_iterations);
- test_deque(num_iterations);
-
- test_cvec(num_iterations);
- test_cdeq(num_iterations);
-
- std::cout << "done.\n";
-
- c_foreach (i, cvec_si, tm) {
- std::cout << i.ref->first << ": " << ((float) i.ref->second / CLOCKS_PER_SEC) << std::endl;
- }
- cvec_si_del(&tm);
- return 0;
-} \ No newline at end of file