2013-01-05 14:16:05 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
#include <DB/IO/ReadHelpers.h>
|
|
|
|
#include <DB/IO/ReadBufferFromFileDescriptor.h>
|
|
|
|
|
2015-10-05 00:44:40 +00:00
|
|
|
#include <DB/Common/Stopwatch.h>
|
2013-01-05 14:16:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace test
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
void readIntText(T & x, DB::ReadBuffer & buf)
|
|
|
|
{
|
|
|
|
bool negative = false;
|
|
|
|
x = 0;
|
|
|
|
|
|
|
|
if (unlikely(buf.eof()))
|
|
|
|
DB::throwReadAfterEOF();
|
|
|
|
|
2014-01-08 16:33:28 +00:00
|
|
|
if (std::is_signed<T>::value && *buf.position() == '-')
|
2013-01-05 14:16:05 +00:00
|
|
|
{
|
|
|
|
++buf.position();
|
|
|
|
negative = true;
|
|
|
|
}
|
2017-03-31 16:00:30 +00:00
|
|
|
|
2013-01-05 14:16:05 +00:00
|
|
|
if (*buf.position() == '0')
|
|
|
|
{
|
|
|
|
++buf.position();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!buf.eof())
|
|
|
|
{
|
|
|
|
if ((*buf.position() & 0xF0) == 0x30)
|
|
|
|
{
|
|
|
|
x *= 10;
|
|
|
|
x += *buf.position() & 0x0F;
|
|
|
|
++buf.position();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-01-08 16:33:28 +00:00
|
|
|
if (std::is_signed<T>::value && negative)
|
2013-01-05 14:16:05 +00:00
|
|
|
x = -x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
DB::ReadBufferFromFileDescriptor in(STDIN_FILENO);
|
|
|
|
Int64 n = 0;
|
|
|
|
size_t nums = 0;
|
|
|
|
|
|
|
|
Stopwatch watch;
|
|
|
|
|
|
|
|
while (!in.eof())
|
|
|
|
{
|
|
|
|
DB::readIntText(n, in);
|
|
|
|
in.ignore();
|
|
|
|
|
|
|
|
//std::cerr << "n: " << n << std::endl;
|
|
|
|
|
|
|
|
++nums;
|
|
|
|
}
|
|
|
|
|
|
|
|
watch.stop();
|
|
|
|
std::cerr << std::fixed << std::setprecision(2)
|
|
|
|
<< "Read " << nums << " numbers (" << in.count() / 1000000.0 << " MB) in " << watch.elapsedSeconds() << " sec., "
|
|
|
|
<< nums / watch.elapsedSeconds() << " num/sec. (" << in.count() / watch.elapsedSeconds() / 1000000 << " MB/s.)"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
catch (const DB::Exception & e)
|
|
|
|
{
|
|
|
|
std::cerr << e.what() << ", " << e.displayText() << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|