Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <thread>
- #include <sys/time.h>
- #include <stdio.h>
- void Thr1(){
- float num;
- for(unsigned int i=0;i<25000U;i++){
- num=1.00001f;
- for(unsigned int j=0;j<1000000U;j++){
- num*=1.00001f;
- }
- }
- }
- void Thr2(){
- float num;
- for(unsigned int i=0;i<25000U;i++){
- num=1.00001f;
- for(unsigned int j=0;j<1000000U;j++){
- num*=1.00001f;
- }
- }
- }
- void Thr3(){
- float num;
- for(unsigned int i=0;i<25000U;i++){
- num=1.00001f;
- for(unsigned int j=0;j<1000000U;j++){
- num*=1.00001f;
- }
- }
- }
- void Thr4(){
- float num;
- for(unsigned int i=0;i<25000U;i++){
- num=1.00001f;
- for(unsigned int j=0;j<1000000U;j++){
- num*=1.00001f;
- }
- }
- }
- int main(){
- timeval n,e;
- double exec_time=0;
- float num;
- std::thread thr1,thr2,thr3,thr4;
- gettimeofday(&n,NULL);
- thr1=std::thread(Thr1);
- thr2=std::thread(Thr2);
- thr3=std::thread(Thr3);
- thr4=std::thread(Thr4);
- thr1.join();
- thr2.join();
- thr3.join();
- thr4.join();
- gettimeofday(&e,NULL);
- exec_time=((double)e.tv_sec-n.tv_sec)*1000.0f+((double)e.tv_usec-n.tv_usec)/1000.0f;
- printf("%f\n",exec_time);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement