summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortylov <[email protected]>2023-07-24 22:57:44 +0200
committertylov <[email protected]>2023-07-24 22:57:44 +0200
commit78ba677b59a8cecd69f733fca1a37ad01b38320f (patch)
tree7a045c9c60ff74f6b04c10ce05921a3b3782c499
parentf1f0c01e798eb3217e62a43de660723173984547 (diff)
downloadSTC-modified-78ba677b59a8cecd69f733fca1a37ad01b38320f.tar.gz
STC-modified-78ba677b59a8cecd69f733fca1a37ad01b38320f.zip
Updated and fixed benchmarks and performance graphs.
-rw-r--r--docs/pics/Figure_1.pngbin58425 -> 60722 bytes
-rw-r--r--include/stc/cstack.h2
-rw-r--r--include/stc/cvec.h2
-rw-r--r--misc/benchmarks/plotbench/cdeq_benchmark.cpp15
-rw-r--r--misc/benchmarks/plotbench/clist_benchmark.cpp8
-rw-r--r--misc/benchmarks/plotbench/cmap_benchmark.cpp8
-rw-r--r--misc/benchmarks/plotbench/cpque_benchmark.cpp3
-rw-r--r--misc/benchmarks/plotbench/csmap_benchmark.cpp8
-rw-r--r--misc/benchmarks/plotbench/cvec_benchmark.cpp15
-rw-r--r--misc/benchmarks/plotbench/plot.py7
10 files changed, 32 insertions, 36 deletions
diff --git a/docs/pics/Figure_1.png b/docs/pics/Figure_1.png
index 263303d2..46a1478f 100644
--- a/docs/pics/Figure_1.png
+++ b/docs/pics/Figure_1.png
Binary files differ
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index f8640ed1..8fb176e1 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -103,7 +103,7 @@ STC_INLINE bool _cx_MEMB(_reserve)(_cx_Self* self, intptr_t n) {
STC_INLINE _cx_value* _cx_MEMB(_append_uninit)(_cx_Self *self, intptr_t n) {
intptr_t len = self->_len;
- if (!_cx_MEMB(_reserve)(self, len + n)) return NULL;
+ if (!_cx_MEMB(_reserve)(self, len*3/2 + n)) return NULL;
self->_len += n;
return self->data + len;
}
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index d08e382f..774f0582 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -316,7 +316,7 @@ _cx_MEMB(_resize)(_cx_Self* self, const intptr_t len, i_key null) {
STC_DEF _cx_value*
_cx_MEMB(_push)(_cx_Self* self, i_key value) {
if (self->_len == self->_cap)
- if (!_cx_MEMB(_reserve)(self, self->_len*3/2 + 4))
+ if (!_cx_MEMB(_reserve)(self, self->_len*2 + 4))
return NULL;
_cx_value *v = self->data + self->_len++;
*v = value;
diff --git a/misc/benchmarks/plotbench/cdeq_benchmark.cpp b/misc/benchmarks/plotbench/cdeq_benchmark.cpp
index 54d7305b..d11b4103 100644
--- a/misc/benchmarks/plotbench/cdeq_benchmark.cpp
+++ b/misc/benchmarks/plotbench/cdeq_benchmark.cpp
@@ -9,10 +9,10 @@
#endif
enum {INSERT, ERASE, FIND, ITER, DESTRUCT, N_TESTS};
-const char* operations[] = {"insert", "erase", "find", "iter", "destruct"};
+const char* operations[] = {"insert", "erase", "access", "iter", "destruct"};
typedef struct { time_t t1, t2; uint64_t sum; float fac; } Range;
typedef struct { const char* name; Range test[N_TESTS]; } Sample;
-enum {SAMPLES = 2, N = 60000000, S = 0x3ffc, R = 4};
+enum {SAMPLES = 2, N = 60000000, R = 4};
uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff;
static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
@@ -44,14 +44,12 @@ Sample test_std_deque() {
c_forrange (N) con.push_back(crand() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
- // Iteration - not inherent find - skipping
- //container::iterator it;
- //c_forrange (S) if ((it = std::find(con.begin(), con.end(), crand() & mask2)) != con.end()) sum += *it;
+ c_forrange (R) c_forrange (i, N) sum += con[i];
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_forrange (R) c_forrange (i, N) sum += con[i];
+ c_forrange (R) for (const auto i: con) sum += i;
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
@@ -89,13 +87,12 @@ Sample test_stc_deque() {
c_forrange (N) cdeq_x_push_back(&con, crand() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
- //cdeq_x_iter it, end = cdeq_x_end(&con);
- //c_forrange (S) if ((it = cdeq_x_find(&con, crand() & mask2)).ref != end.ref) sum += *it.ref;
+ c_forrange (R) c_forrange (i, N) sum += *cdeq_x_at(&con, i);
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_forrange (R) c_forrange (i, N) sum += con.data[i];
+ c_forrange (R) c_foreach (i, cdeq_x, con) sum += *i.ref;
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
diff --git a/misc/benchmarks/plotbench/clist_benchmark.cpp b/misc/benchmarks/plotbench/clist_benchmark.cpp
index 01bfbf83..8fdfddba 100644
--- a/misc/benchmarks/plotbench/clist_benchmark.cpp
+++ b/misc/benchmarks/plotbench/clist_benchmark.cpp
@@ -9,10 +9,10 @@
#endif
enum {INSERT, ERASE, FIND, ITER, DESTRUCT, N_TESTS};
-const char* operations[] = {"insert", "erase", "find", "iter", "destruct"};
+const char* operations[] = {"insert", "erase", "access", "iter", "destruct"};
typedef struct { time_t t1, t2; uint64_t sum; float fac; } Range;
typedef struct { const char* name; Range test[N_TESTS]; } Sample;
-enum {SAMPLES = 2, N = 10000000, S = 0x3ffc, R = 4};
+enum {SAMPLES = 2, N = 10000000, R = 4};
uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff;
static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
@@ -45,7 +45,6 @@ Sample test_std_forward_list() {
size_t sum = 0;
container::iterator it;
// Iteration - not inherent find - skipping
- //c_forrange (S) if ((it = std::find(con.begin(), con.end(), crand() & mask2)) != con.end()) sum += *it;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
@@ -86,8 +85,7 @@ Sample test_stc_forward_list() {
c_forrange (N) clist_x_push_front(&con, crand() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
- //clist_x_iter it, end = clist_x_end(&con);
- //c_forrange (S) if ((it = clist_x_find(&con, crand() & mask2)).ref != end.ref) sum += *it.ref;
+ //clist iteration - skipping
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
diff --git a/misc/benchmarks/plotbench/cmap_benchmark.cpp b/misc/benchmarks/plotbench/cmap_benchmark.cpp
index 6b2edbd7..c7957bb7 100644
--- a/misc/benchmarks/plotbench/cmap_benchmark.cpp
+++ b/misc/benchmarks/plotbench/cmap_benchmark.cpp
@@ -8,7 +8,7 @@
#endif
enum {INSERT, ERASE, FIND, ITER, DESTRUCT, N_TESTS};
-const char* operations[] = {"insert", "erase", "find", "iter", "destruct"};
+const char* operations[] = {"insert", "erase", "access", "iter", "destruct"};
typedef struct { time_t t1, t2; uint64_t sum; float fac; } Range;
typedef struct { const char* name; Range test[N_TESTS]; } Sample;
enum {SAMPLES = 2, N = 2000000, R = 4};
@@ -47,12 +47,14 @@ Sample test_std_unordered_map() {
s.test[FIND].t1 = clock();
size_t sum = 0;
container::iterator it;
- c_forrange (N) if ((it = con.find(crand() & mask1)) != con.end()) sum += it->second;
+ c_forrange (N)
+ if ((it = con.find(crand() & mask1)) != con.end())
+ sum += it->second;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_forrange (R) for (auto i: con) sum += i.second;
+ c_forrange (R) for (const auto& i: con) sum += i.second;
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
diff --git a/misc/benchmarks/plotbench/cpque_benchmark.cpp b/misc/benchmarks/plotbench/cpque_benchmark.cpp
index 6c62ae3e..aafc9eb0 100644
--- a/misc/benchmarks/plotbench/cpque_benchmark.cpp
+++ b/misc/benchmarks/plotbench/cpque_benchmark.cpp
@@ -37,7 +37,8 @@ void stc_test()
{
int N = 10000000;
- c_auto (cpque_f, pq)
+ cpque_f pq = {0};
+ c_defer(cpque_f_drop(&pq))
{
csrand(seed);
clock_t start = clock();
diff --git a/misc/benchmarks/plotbench/csmap_benchmark.cpp b/misc/benchmarks/plotbench/csmap_benchmark.cpp
index 60f2db49..480163ed 100644
--- a/misc/benchmarks/plotbench/csmap_benchmark.cpp
+++ b/misc/benchmarks/plotbench/csmap_benchmark.cpp
@@ -8,7 +8,7 @@
#endif
enum {INSERT, ERASE, FIND, ITER, DESTRUCT, N_TESTS};
-const char* operations[] = {"insert", "erase", "find", "iter", "destruct"};
+const char* operations[] = {"insert", "erase", "access", "iter", "destruct"};
typedef struct { time_t t1, t2; uint64_t sum; float fac; } Range;
typedef struct { const char* name; Range test[N_TESTS]; } Sample;
enum {SAMPLES = 2, N = 1000000, R = 4};
@@ -47,12 +47,14 @@ Sample test_std_map() {
s.test[FIND].t1 = clock();
size_t sum = 0;
container::iterator it;
- c_forrange (N) if ((it = con.find(crand() & mask1)) != con.end()) sum += it->second;
+ c_forrange (N)
+ if ((it = con.find(crand() & mask1)) != con.end())
+ sum += it->second;
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_forrange (R) for (auto i: con) sum += i.second;
+ c_forrange (R) for (const auto& i: con) sum += i.second;
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
diff --git a/misc/benchmarks/plotbench/cvec_benchmark.cpp b/misc/benchmarks/plotbench/cvec_benchmark.cpp
index 45b9cf93..fb10653a 100644
--- a/misc/benchmarks/plotbench/cvec_benchmark.cpp
+++ b/misc/benchmarks/plotbench/cvec_benchmark.cpp
@@ -9,10 +9,10 @@
#endif
enum {INSERT, ERASE, FIND, ITER, DESTRUCT, N_TESTS};
-const char* operations[] = {"insert", "erase", "find", "iter", "destruct"};
+const char* operations[] = {"insert", "erase", "access", "iter", "destruct"};
typedef struct { time_t t1, t2; uint64_t sum; float fac; } Range;
typedef struct { const char* name; Range test[N_TESTS]; } Sample;
-enum {SAMPLES = 2, N = 40000000, S = 0x3ffc, R = 4};
+enum {SAMPLES = 2, N = 60000000, R = 4};
uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff;
static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
@@ -42,14 +42,12 @@ Sample test_std_vector() {
c_forrange (N) con.push_back(crand() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
- //container::iterator it;
- // Iteration - not inherent find - skipping
- //c_forrange (S) if ((it = std::find(con.begin(), con.end(), crand() & mask2)) != con.end()) sum += *it;
+ c_forrange (R) c_forrange (i, N) sum += con[i];
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_forrange (R) c_forrange (i, N) sum += con[i];
+ c_forrange (R) for (const auto i: con) sum += i;
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
@@ -85,13 +83,12 @@ Sample test_stc_vector() {
c_forrange (N) cvec_x_push(&con, crand() & mask2);
s.test[FIND].t1 = clock();
size_t sum = 0;
- //cvec_x_iter it, end = cvec_x_end(&con);
- //c_forrange (S) if ((it = cvec_x_find(&con, crand() & mask2)).ref != end.ref) sum += *it.ref;
+ c_forrange (R) c_forrange (i, N) sum += con.data[i];
s.test[FIND].t2 = clock();
s.test[FIND].sum = sum;
s.test[ITER].t1 = clock();
sum = 0;
- c_forrange (R) c_forrange (i, N) sum += con.data[i];
+ c_forrange (R) c_foreach (i, cvec_x, con) sum += *i.ref;
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
s.test[DESTRUCT].t1 = clock();
diff --git a/misc/benchmarks/plotbench/plot.py b/misc/benchmarks/plotbench/plot.py
index 8e684ccc..4a02c6b2 100644
--- a/misc/benchmarks/plotbench/plot.py
+++ b/misc/benchmarks/plotbench/plot.py
@@ -13,12 +13,11 @@ if n > 0:
df = df[df.Compiler == comp[n]]
g = sns.catplot(data=df, x='Method', y='Seconds', hue='Library', col='C', kind='bar', orient='v',
- errorbar=('ci', 68), legend=False, col_wrap=2, sharex=False, aspect=1.4, height=3.1)
+ errorbar=('ci', 68), legend=False, col_wrap=2, sharex=False, aspect=1.4, height=3.0)
g.set_xlabels('')
-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.add_legend(bbox_to_anchor=(0.75, 0.2), borderaxespad=0)
+g.fig.subplots_adjust(top=0.90, left=0.08, right=0.98, bottom=0.04, hspace=0.4)
g.fig.suptitle('Benchmark STC vs c++ std containers: %s' % comp[n], fontsize=15, y=0.98)
plt.show()