Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
cin / scanf comparison
Comparison between cin and scanf
Usage:
make
./rand > rand.txt
Ctrl-C after a few seconds
wc rand.txt
time ./xor-c < rand.txt
time ./xor-cpp < rand.txt
all: xor-c xor-cpp xor-cpp-noflush rand
test: xor-c xor-cpp xor-cpp-noflush
time ./xor-c < rand.txt
time ./xor-cpp < rand.txt
time ./xor-cpp-noflush < rand.txt
rand: rand.c
gcc -Wall rand.c -o rand
xor-c: xor.c
gcc -Wall -O4 xor.c -o xor-c
xor-cpp: xor.cc
g++ -Wall -O4 xor.cc -o xor-cpp
xor-cpp-noflush: xor-noflush.cc
g++ -Wall -O4 xor-noflush.cc -o xor-cpp-noflush
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(int argc, char **argv) {
srand(time(NULL));
while (1)
printf("%d\n", rand());
}
#include <iostream>
int main(int argc, char **argv) {
int parity = 0;
int x;
std::ios::sync_with_stdio(false);
while (std::cin >> x)
parity ^= x;
std::cout << parity << std::endl;
return 0;
}
#include <stdio.h>
int main(int argc, char **argv) {
int parity = 0;
int x;
while (1 == scanf("%d", &x))
parity ^= x;
printf("%d\n", parity);
return 0;
}
#include <iostream>
int main(int argc, char **argv) {
int parity = 0;
int x;
while (std::cin >> x)
parity ^= x;
std::cout << parity << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.