Jump to content
xisto Community
WaCo

Speed And The Incrementation Methods essay

Recommended Posts

"Speed of various incremetation methods"

 

1) Method one

[tomek@localhost ebooks]$ LEGAL=1 LEGAL_2=1; LEGAL_3=1;for i in `seq 100000`; do LEGAL=$(( $LEGAL + 1 ));LEGAL_2=$(( $LEGAL_2 + 1 )); LEGAL_3=$(( $LEGAL_3 + 1 ));  done; echo legal\'s value is "$LEGAL"
Avarage amount of time that the process took: 9 seconds 29 hundredth.

 

 

 

2) Method two

[tomek@localhost ebooks]$ LEGAL=1 LEGAL_2=1;LEGAL_3=1;for i in `seq 100000`; do LEGAL=$[LEGAL + 1];LEGAL_2=$[LEGAL_2 + 1];LEGAL_3=$[LEGAL_3 + 1];  done;echo legal\'s value is "$LEGAL"
Avarage amount of time that the process took: 6 seconds 99 hundredth.

 

 

 

3) Method three

[tomek@localhost ebooks]$ LEGAL=1 LEGAL_2=1; LEGAL_3=1;for i in `seq 100000`; do LEGAL=`echo $LEGAL + 1 | bc`;LEGAL_2=`echo $LEGAL_2 + 1 | bc`;LEGAL_3=`echo $LEGAL_3 + 1 | bc`;  done;echo legal\'s value is "$LEGAL"
Avarage amount of time that the process took: 5 000 seconds.

 

 

 

4) Metoda four

[tomek@localhost ebooks]$ LEGAL=1 LEGAL_2=1; LEGAL_3=1;for i in `seq 100000`; do LEGAL=`expr $LEGAL + 1`;LEGAL_2=`expr $LEGAL_2 + 1`;LEGAL_3=`expr $LEGAL_3 + 1`;  done;echo legal\'s value is "$LEGAL"
Avarage amount of time that the process took: 2 000 seconds.

 

 

 

5) C++ example for comprehension

#include <iostream>using namespace std;int main(){   float a;  for ( a=1; a <= 10000000; a++ ) { /*  100 x more than in bash !!!  */  }  cout << a;return 0;}
Avarage amount of time that the process took: not even a second.

 

Conclusion: The best incrementation method is second method, but compared to hightech programming languages it's still very slow.

 

Notes: tests were held on Duron 733 Mhz, 128 mb ram, riva tnt 2 32 mb.

 


[Added 2005-08-11, 07:49:21]

Share this post


Link to post
Share on other sites

The comparason to c++ is not fair.
You will probably find that the c++ compiler is optimising your code, and replacing

 for ( a=1; a <= 10000000; a++ ) { /*  100 x more than in bash !!!  */ }

with the following code

a=10000000;

both pieces of code achieve the same end result.

try compiling the the zero optimise flag -O0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.