benchmarking

Why is my Rust version of “wc” slower than the one from GNU coreutils?

时间秒杀一切 提交于 2020-07-18 05:06:07
问题 Consider this program: use std::io::BufRead; use std::io; fn main() { let mut n = 0; let stdin = io::stdin(); for _ in stdin.lock().lines() { n += 1; } println!("{}", n); } Why is it over 10x as slow as the GNU version of wc? Take a look at how I measure it: $ yes | dd count=1000000 | wc -l 256000000 1000000+0 records in 1000000+0 records out 512000000 bytes (512 MB, 488 MiB) copied, 1.16586 s, 439 MB/s $ yes | dd count=1000000 | ./target/release/wc 1000000+0 records in 1000000+0 records out

Why measuring the execution time of a loop gives different results execution after execution? [duplicate]

Deadly 提交于 2020-07-10 09:37:37
问题 This question already has an answer here : Why the execution time of a million double-int conversion is the same as an empty loop? (1 answer) Closed 8 months ago . I know it's stupid, but I still have to ask this question because it's been bothering me for days. I use a variety of methods to test, but the results vary widely. The execution time of a million double-int conversions is the same as empty loop 回答1: Good and smart question. The Elapsed result of a StopWatch varies because modern

Why measuring the execution time of a loop gives different results execution after execution? [duplicate]

橙三吉。 提交于 2020-07-10 09:37:12
问题 This question already has an answer here : Why the execution time of a million double-int conversion is the same as an empty loop? (1 answer) Closed 8 months ago . I know it's stupid, but I still have to ask this question because it's been bothering me for days. I use a variety of methods to test, but the results vary widely. The execution time of a million double-int conversions is the same as empty loop 回答1: Good and smart question. The Elapsed result of a StopWatch varies because modern

Why measuring the execution time of a loop gives different results execution after execution? [duplicate]

此生再无相见时 提交于 2020-07-10 09:37:12
问题 This question already has an answer here : Why the execution time of a million double-int conversion is the same as an empty loop? (1 answer) Closed 8 months ago . I know it's stupid, but I still have to ask this question because it's been bothering me for days. I use a variety of methods to test, but the results vary widely. The execution time of a million double-int conversions is the same as empty loop 回答1: Good and smart question. The Elapsed result of a StopWatch varies because modern

Benchmarking matrix multiplication performance: C++ (eigen) is much slower than Python

五迷三道 提交于 2020-06-24 05:25:18
问题 I am trying to estimate how good is Python performance comparing to C++. Here is my Python code: a=np.random.rand(1000,1000) #type is automaically float64 b=np.random.rand(1000,1000) c=np.empty((1000,1000),dtype='float64') %timeit a.dot(b,out=c) #15.5 ms ± 560 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) And here is my C++ code that I compile with Xcode in release regime: #include <iostream> #include <Dense> #include <time.h> using namespace Eigen; using namespace std; int main

Simple for() loop benchmark takes the same time with any loop bound

核能气质少年 提交于 2020-06-21 05:22:06
问题 I'm willing to write a code that makes my CPU execute some operations and see how much time does he take to solve them. I wanted to make a loop going from i=0 to i<5000 and then multiplying i by a constant number and time that. I've ended up with this code, it has no errors but it only takes 0.024 seconds to execute the code even if I change the loop i<49058349083 or if i<2 it takes the same amount of time. Whats the error? PD: I started yesterday learning C++ i'm sorry if this is a really

Is it faster to prepend to a string with substr?

浪子不回头ぞ 提交于 2020-05-14 18:42:28
问题 I just found code that prepends with substr( $str, 0, 0, $prepend ) my $foo = " world!" substr( $foo, 0, 0, "Hello " ); Is this any faster than my $foo = " world!" $foo = "Hello $foo"; 回答1: Optrees If we compare the two optrees the top has b <@> substr[t2] vK/4 ->c - <0> ex-pushmark s ->7 7 <0> padsv[$foo:2,3] sM ->8 8 <$> const[IV 0] s ->9 9 <$> const[IV 0] s ->a a <$> const[PV "Hello "] s ->b While the bottom has 8 <+> multiconcat(" world!",-1,7)[$foo:2,3] sK/TARGMY,STRINGIFY ->9 - <0> ex

How to do benchmarking for C/C++ code accurately?

穿精又带淫゛_ 提交于 2020-05-14 09:02:30
问题 I'm asking regarding answers on this question, In my answer I first just got the time before and after the loops and printed out their difference, But as an update for @cigien s answer, it seems that I've done benchmarking inaccurately by not warming up the code. What is warming up of the code? I think what happened here is that the string was moved to the cache first and that made the benchmarking results for the following loops close to each other. In my old answer, the first benchmarking

For-loop efficiency: merging loops

六眼飞鱼酱① 提交于 2020-05-11 05:47:47
问题 I have always had the idea that reducing the number of iterations is the way to making programs more efficient. Since I never really confirmed that, I set out to test this. I made the following C++ program that measures the time of two different functions: The first function does a single large loop and uses a set of variables. The second function does multiple equally large loops, but a single loop per variable. Complete test code: #include <iostream> #include <chrono> using namespace std;

For-loop efficiency: merging loops

为君一笑 提交于 2020-05-11 05:47:45
问题 I have always had the idea that reducing the number of iterations is the way to making programs more efficient. Since I never really confirmed that, I set out to test this. I made the following C++ program that measures the time of two different functions: The first function does a single large loop and uses a set of variables. The second function does multiple equally large loops, but a single loop per variable. Complete test code: #include <iostream> #include <chrono> using namespace std;