Skip to content

Instantly share code, notes, and snippets.

@depp
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save depp/b78b43cb7108ae0d79fb to your computer and use it in GitHub Desktop.
Save depp/b78b43cb7108ae0d79fb to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#undef CUSTOM_BUFFER
#if defined CUSTOM_BUFFER
static const int BUFFER_SIZE = 1024 * 16;
#endif
int main()
{
#if defined CUSTOM_BUFFER
char buffer[BUFFER_SIZE];
std::cin.rdbuf()->pubsetbuf(buffer, BUFFER_SIZE);
#endif
std::ios_base::sync_with_stdio(false);
std::vector<int> data;
int input;
while (std::cin >> input)
{
data.push_back(input);
}
std::cout << "Data loaded." << std::endl;
return 0;
}
import sys
data = [int(x) for x in sys.stdin.read().split()]
$ c++ -O2 -Wall -Wextra test.cpp
$ time ./a.out < million-integers.txt
Data loaded.
./a.out < million-integers.txt 4.06s user 0.01s system 99% cpu 4.072 total
$ time python test.py < million-integers.txt
python3 test.py < million-integers.txt 0.38s user 0.06s system 99% cpu 0.438 total
$ c++ --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment