mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-05 09:20:29 +00:00
Add more big string benchmarks
This commit is contained in:
parent
e2e6867349
commit
03f3f62fc5
1 changed files with 38 additions and 5 deletions
|
@ -40,9 +40,14 @@
|
||||||
printf("%10g ns %2dx %s\n", nanos, (ITERATIONS), #CODE); \
|
printf("%10g ns %2dx %s\n", nanos, (ITERATIONS), #CODE); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
constexpr auto big_c = "aaaaaaaaaaaaaaaaaaaaaaaa";
|
||||||
|
constexpr auto small_c = "aaaaaaaaaaaaaaaaaaaaaaa";
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
|
const ctl::string_view big(big_c), small(small_c);
|
||||||
|
|
||||||
BENCH(10000000, 1, {
|
BENCH(10000000, 1, {
|
||||||
ctl::string s;
|
ctl::string s;
|
||||||
s.append("hello ");
|
s.append("hello ");
|
||||||
|
@ -70,6 +75,13 @@ main()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
BENCH(1000000, 24, {
|
||||||
|
ctl::string s;
|
||||||
|
for (int i = 0; i < 24; ++i) {
|
||||||
|
s.append('a');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
BENCH(1000000, 32, {
|
BENCH(1000000, 32, {
|
||||||
ctl::string s;
|
ctl::string s;
|
||||||
for (int i = 0; i < 32; ++i) {
|
for (int i = 0; i < 32; ++i) {
|
||||||
|
@ -77,20 +89,41 @@ main()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
BENCH(1000000, 1, { ctl::string s("hello world"); });
|
BENCH(1000000, 1, { ctl::string s(small_c); });
|
||||||
|
|
||||||
|
BENCH(1000000, 1, { ctl::string s(small); });
|
||||||
|
|
||||||
{
|
{
|
||||||
ctl::string s("hello world");
|
ctl::string small_copy("hello world");
|
||||||
BENCH(1000000, 1, { ctl::string s2(s); });
|
BENCH(1000000, 1, { ctl::string s2(small_copy); });
|
||||||
}
|
}
|
||||||
|
|
||||||
BENCH(1000000, 1, {
|
BENCH(1000000, 1, {
|
||||||
ctl::string s("hello world");
|
ctl::string s(small);
|
||||||
ctl::string s2(std::move(s));
|
ctl::string s2(std::move(s));
|
||||||
});
|
});
|
||||||
|
|
||||||
BENCH(1000000, 1, {
|
BENCH(1000000, 1, {
|
||||||
ctl::string s("hello world");
|
ctl::string s(small);
|
||||||
|
ctl::string s2(s);
|
||||||
|
});
|
||||||
|
|
||||||
|
BENCH(1000000, 1, { ctl::string s(big_c); });
|
||||||
|
|
||||||
|
BENCH(1000000, 1, { ctl::string s(big); });
|
||||||
|
|
||||||
|
{
|
||||||
|
ctl::string big_copy(big);
|
||||||
|
BENCH(1000000, 1, { ctl::string s2(big_copy); });
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCH(1000000, 1, {
|
||||||
|
ctl::string s(big);
|
||||||
|
ctl::string s2(std::move(s));
|
||||||
|
});
|
||||||
|
|
||||||
|
BENCH(1000000, 1, {
|
||||||
|
ctl::string s(big);
|
||||||
ctl::string s2(s);
|
ctl::string s2(s);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue