diff options
| author | Tyge Løvset <[email protected]> | 2020-03-14 12:56:41 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-03-14 12:56:41 +0100 |
| commit | 2052a78c985b176a107e43e304689c841e3a635e (patch) | |
| tree | 239909d6ef88dc1e8fc275c51bf6df189ecf9f4e /benchmark.cpp | |
| parent | e93ca68c1aa23d004f8c6b46b08079ee11fb2b66 (diff) | |
| download | STC-modified-2052a78c985b176a107e43e304689c841e3a635e.tar.gz STC-modified-2052a78c985b176a107e43e304689c841e3a635e.zip | |
Add files via upload
Diffstat (limited to 'benchmark.cpp')
| -rw-r--r-- | benchmark.cpp | 63 |
1 files changed, 55 insertions, 8 deletions
diff --git a/benchmark.cpp b/benchmark.cpp index ebb3af2f..386a0bc7 100644 --- a/benchmark.cpp +++ b/benchmark.cpp @@ -13,7 +13,7 @@ int main() {
clock_t before, difference;
CMap_ii map = cmap_initializer;
-
+ CMapEntry_ii* entry;
uint64_t checksum = 0, erased, get;
const size_t N = 50000000;
@@ -30,9 +30,10 @@ int main() case 1:
checksum += ++cmap_ii_put(&map, rnd, i-1)->value;
break;
- //case 0:
case 2:
- if (cmap_size(map) > 0) erased += cmap_ii_erase(&map, rnd);
+ entry = cmap_ii_get(map, rnd);
+ if (entry) { checksum += entry->value; ++erased; }
+ /*erased +=*/ cmap_ii_erase(&map, rnd);
break;
case 3:
get += (cmap_ii_get(map, rnd) != NULL);
@@ -42,9 +43,10 @@ int main() difference = clock() - before;
printf("CMap_ii: size: %llu, time: %f, sum: %llu, erased: %llu, get %llu\n", cmap_size(map), 1.0 * difference / CLOCKS_PER_SEC, checksum, erased, get);
//c_foreach (i, cmap_ii, map) sum += cmap_ii_get(map, i.item->key)->value;
- cmap_ii_destroy(&map);
+ //cmap_ii_destroy(&map);
- std::unordered_map<int64_t, int64_t> map2;
+ std::unordered_map<int64_t, int64_t> map2, map3;
+ std::unordered_map<int64_t, int64_t>::const_iterator iter;
//map2.reserve(N);
srand(123);
before = clock();
@@ -56,9 +58,10 @@ int main() case 1:
checksum += ++(map2[rnd] = i-1);
break;
- //case 0:
case 2:
- if (map2.size() > 0) erased += map2.erase(rnd);
+ iter = map2.find(rnd);
+ if (iter != map2.end()) { checksum += iter->second; ++erased; }
+ /*erased +=*/ map2.erase(rnd);
break;
case 3:
get += (map2.find(rnd) != map2.end());
@@ -66,6 +69,50 @@ int main() }
}
difference = clock() - before;
- printf("std::um: size: %llu, time: %f, sum: %llu, erased: %llu, get %llu\n", cmap_size(map), 1.0 * difference / CLOCKS_PER_SEC, checksum, erased, get);
+ printf("std::um: size: %llu, time: %f, sum: %llu, erased: %llu, get %llu\n", map2.size(), 1.0 * difference / CLOCKS_PER_SEC, checksum, erased, get);
+
+ c_foreach (i, cmap_ii, map) map3[ i.item->key ] = i.item->value;
+ printf("map3: %llu, %d\n", map3.size(), map2 == map3);
+
+
+#if 0
+ srand(123);
+ const size_t N = 40000000;
+ CMap_ii map = cmap_initializer;
+ CMapEntry_ii* entry;
+ uint64_t checksum = 0, erased = 0, get = 0;
+ uint64_t checksum2 = 0, erased2 = 0, get2 = 0;
+ std::unordered_map<int64_t, int64_t> map2, map3;
+ std::unordered_map<int64_t, int64_t>::const_iterator iter;
+ srand(123);
+ for (size_t i = 0; i < N; ++i) {
+ int64_t rnd = rand();
+ int op = rand() >> 13;
+ switch (op) {
+ case 1:
+ checksum += ++cmap_ii_put(&map, rnd, i-1)->value;
+ checksum2 += ++(map2[rnd] = i-1);
+ if (rnd == 16459) printf("%llu: put 16459: %llu\n", i, erased);
+ break;
+ case 2:
+ erased += cmap_ii_erase(&map, rnd);
+ erased2 += map2.erase(rnd);
+ if (erased != erased2) {
+ printf("%llu: era %llu: %llu, %llu\n", i, rnd, erased, erased2);
+ exit(0);
+ }
+ if (rnd == 16459) printf("%llu: era 16459: %llu\n", i, erased);
+ break;
+ case 3:
+ get += (cmap_ii_get(map, rnd) != NULL);
+ get2 += (map2.find(rnd) != map2.end());
+ break;
+ }
+ }
+ printf("cmap_ii: size: %llu, sum: %llu, erased: %llu, get %llu\n", cmap_size(map), checksum, erased, get);
+ printf("std::um: size: %llu, sum: %llu, erased: %llu, get %llu\n", map2.size(), checksum2, erased2, get2);
+#endif
+
+ cmap_ii_destroy(&map);
map2.clear();
}
\ No newline at end of file |
