Your C++ code may be much slower in reading lines from stdin than Python by default.

Assume following simple case:
// C++ code
while (std::cin) {
    getline(std::cin, input_line);
    if (!std::cin.eof()) {
# Python code
for line in  sys.stdin:
    count += 1

$ cat test_lines | ./readline_test_cpp
Saw 5570000 lines in 9 seconds.  Crunch speed: 618889

$cat test_lines | ./
Read 5570000 lines in 1 seconds. LPS: 5570000

Reason: by default, std::cin is synchronized with stdio, which causes it to avoid any input buffering. If you add this to the top of your main, you should see much better performance:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s