ubuntu 14.04, g++ 4.8
81.700000, 187.500000
ubuntu 14.04, clang++-3.8
76.400000, 186.800000
| #include <chrono> | |
| #include <functional> | |
| #include <iostream> | |
| typedef std::function<void()> Reader; | |
| uint64_t bench(uint64_t iterations, const Reader& reader) { | |
| auto start = std::chrono::system_clock::now(); | |
| for (uint64_t i = 0; i < iterations; i++) { | |
| reader(); | |
| } | |
| auto end = std::chrono::system_clock::now(); | |
| return std::chrono::duration_cast<std::chrono::milliseconds>(end - | |
| start) | |
| .count(); | |
| } | |
| int main() { | |
| uint64_t iter = 250000; | |
| uint64_t runs = 10; | |
| double t_scan = 0, t_cin = 0; | |
| for (uint64_t x = 0; x < runs; x++) { | |
| t_scan += bench(iter, []() { | |
| int64_t a = 0, b = 0, c = 0; | |
| scanf("%ld %ld %ld", &a, &b, &c); | |
| }); | |
| t_cin += bench(iter, []() { | |
| int64_t a = 0, b = 0, c = 0; | |
| std::cin >> a >> b >> c; | |
| }); | |
| } | |
| printf("%lf, %lf\n", t_scan / runs, t_cin / runs); | |
| } |