Skip to content

Commit

Permalink
stdio
Browse files Browse the repository at this point in the history
  • Loading branch information
trcrsired committed Jan 22, 2024
1 parent 13102d5 commit 614efdb
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
28 changes: 28 additions & 0 deletions benchmark/0002.file_io_tsc/1mtime/fstream.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <fast_io.h>
#include <fast_io_device.h>
#include <fast_io_legacy.h>
#include <fast_io_driver/timer.h>
#include <vector>

int main()
{
constexpr std::size_t N(1000000);
{
fast_io::timer t(u8"output");
fast_io::filebuf_file obf(u8"fstream.txt", fast_io::open_mode::out);
std::ostream fout(obf.fb);
for (std::size_t i{}; i != N; ++i)
{
fout << i;
obf.fb->sputc('\n');
}
}
std::vector<std::size_t> vec(N);
{
fast_io::timer t(u8"input");
fast_io::filebuf_file ibf(u8"fstream.txt", fast_io::open_mode::in);
std::istream fin(ibf.fb);
for (std::size_t i{}; i != N; ++i)
fin >> vec[i];
}
}
23 changes: 23 additions & 0 deletions benchmark/0002.file_io_tsc/1mtime/iobuf_file.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <fast_io.h>
#include <fast_io_device.h>
#include <fast_io_driver/timer.h>
#include <vector>
using namespace fast_io::io;

int main()
{
constexpr std::size_t N(1000000);
{
fast_io::timer t(u8"output");
fast_io::obuf_file obf("iobuf_file.txt");
for (std::size_t i{}; i != N; ++i)
println(obf, i);
}
std::vector<std::size_t> vec(N);
{
fast_io::timer t(u8"input");
fast_io::ibuf_file ibf("iobuf_file.txt");
for (std::size_t i{}; i != N; ++i)
scan(ibf, vec[i]);
}
}
22 changes: 22 additions & 0 deletions benchmark/0002.file_io_tsc/1mtime/stdio.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <fast_io.h>
#include <fast_io_device.h>
#include <fast_io_driver/timer.h>
#include <vector>

int main()
{
constexpr std::size_t N(1000000);
{
fast_io::timer t(u8"output");
fast_io::c_file obf(u8"stdio.txt", fast_io::open_mode::out);
for (std::size_t i{}; i != N; ++i)
fprintf(obf.fp, "%zu\n", i);
}
std::vector<std::size_t> vec(N);
{
fast_io::timer t(u8"input");
fast_io::c_file ibf(u8"stdio.txt", fast_io::open_mode::in);
for (std::size_t i{}; i != N; ++i)
fscanf(ibf.fp, "%zu", vec.data() + i);
}
}

0 comments on commit 614efdb

Please sign in to comment.