Last active
August 29, 2015 14:02
-
-
Save depp/b78b43cb7108ae0d79fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
data = [int(x) for x in sys.stdin.read().split()] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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