Saturday, June 25, 2016

std::move example

Here is an example of move semantics:

When line 24 is used:

nonbonding@castor-ub:~/dnonbonding/tmp/rvalue$ g++ -std=c++11 c.cpp && time ./a.out
200000000
200000000

real 0m31.475s
user 0m24.932s
sys 0m4.604s

When line 25 is used instead of line 24:

nonbonding@castor-ub:~/dnonbonding/tmp/rvalue$ g++ -std=c++11 c.cpp && time ./a.out 
200000000
0

real 0m17.334s
user 0m16.708s
sys 0m0.440s

Execution time was reduced by almost a half!

No comments:

Post a Comment