Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 29 additions & 33 deletions src/0002.concatstring/concat_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,39 @@
#include <fast_io.h>
#include <version>

struct benchmark_return
{
std::size_t total_size{};
fast_io::unix_timestamp timestamp{};
struct benchmark_return {
std::size_t total_size{};
fast_io::unix_timestamp timestamp{};
};

template <typename Func>
inline benchmark_return benchmark(Func meth)
{
std::size_t total_size{};
auto start{fast_io::posix_clock_gettime(fast_io::posix_clock_id::monotonic_raw)};
for (std::uint_least16_t r{}; r != 256; ++r)
{
for (std::uint_least16_t g{}; g != 256; ++g)
{
for (std::uint_least16_t b{}; b != 256; ++b)
{
total_size += meth(static_cast<::std::uint_least8_t>(r), static_cast<::std::uint_least8_t>(g),
static_cast<::std::uint_least8_t>(b))
.size();
}
}
}
return {total_size, fast_io::posix_clock_gettime(fast_io::posix_clock_id::monotonic_raw) - start};
template <typename Func> inline benchmark_return benchmark(Func meth) {
std::size_t total_size{};
auto start{
fast_io::posix_clock_gettime(fast_io::posix_clock_id::monotonic_raw)};
for (std::uint_least16_t r{}; r != 256; ++r) {
for (std::uint_least16_t g{}; g != 256; ++g) {
for (std::uint_least16_t b{}; b != 256; ++b) {
total_size += meth(static_cast<::std::uint_least8_t>(r),
static_cast<::std::uint_least8_t>(g),
static_cast<::std::uint_least8_t>(b))
.size();
}
}
}
return {total_size,
fast_io::posix_clock_gettime(fast_io::posix_clock_id::monotonic_raw) -
start};
}

inline auto color_concat (std::uint_least8_t r, std::uint_least8_t g, std::uint_least8_t b)
{
return ::fast_io::concat("Red: ", r, ", Green: ", g, ", Blue: ", b);
inline auto color_concat(std::uint_least8_t r, std::uint_least8_t g,
std::uint_least8_t b) {
return ::fast_io::concat_std("Red: ", r, ", Green: ", g, ", Blue: ", b);
}


int main()
{
auto concat_time = benchmark(color_concat);
using namespace fast_io::io;
print("fast_io::concat (total size: ",
concat_time.total_size, ") took ", concat_time.timestamp,
"s.\n");
int main() {
auto concat_time = benchmark(color_concat);
using namespace fast_io::io;
perrln("concat_string:", concat_time.timestamp, "s");
print("fast_io::concat_std (total size: ", concat_time.total_size, ") took ",
concat_time.timestamp, "s.\n");
}
2 changes: 1 addition & 1 deletion src/0006.vector_push_back/vector_push_back.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

int main()
{
constexpr ::std::size_t N{20000000};
constexpr ::std::size_t N{5000000};
::std::size_t capacity{};
{
::fast_io::timer timer_total(u8"::fast_io::vector<::std::size_t>");
Expand Down
Loading