Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int find = 2500;
- static int sideEffect = 0;
- bool function1()
- {
- sideEffect *= find;
- bool found = false;
- for (int bar =0; !found && bar < 100; ++bar)
- for(int foo = 0; !found && foo < 100; ++foo)
- if (foo * bar == find)
- found = true;
- return found;
- }
- bool function2()
- {
- sideEffect *= find;
- for (int bar =0; bar < 100; ++bar)
- for(int foo = 0; foo < 100; ++foo)
- if (foo * bar == find)
- return 1;
- return 0;
- }
- bool function3()
- {
- sideEffect *= find;
- bool result = false;
- for (int bar =0; bar < 100; ++bar)
- for(int foo = 0; foo < 100; ++foo)
- if ( (result=(foo * bar == find)) )
- goto end;
- end:
- return result;
- }
- bool function4()
- {
- try
- {
- sideEffect *= find;
- for (int bar =0; bar < 100; ++bar)
- for(int foo = 0; foo < 100; ++foo)
- if (foo * bar == find)
- throw true;
- }
- catch(bool b) { return b; }
- return 0;
- }
- void Test()
- {
- scanf("%d", &find);
- u8 stackMem[1024];
- StackAlloc stack( stackMem, 1024 );
- Scope scope( stack, "main" );
- Timer& timer = *eiNew(scope, Timer)();
- int r = 0;
- double b, e;
- b = timer.Elapsed();
- for( int i=0; i!=10000; ++i )
- r += (int)function2();
- e = timer.Elapsed();
- double t1 = e-b;
- b = timer.Elapsed();
- //for( int j=0; j!=10000; ++j )
- for( int i=0; i!=100000; ++i )
- r += (int)function2();
- e = timer.Elapsed();
- t1 = e-b;
- b = timer.Elapsed();
- //for( int j=0; j!=10000; ++j )
- for( int i=0; i!=100000; ++i )
- r += (int)function1();
- e = timer.Elapsed();
- double t2 = e-b;
- b = timer.Elapsed();
- //for( int j=0; j!=10000; ++j )
- for( int i=0; i!=100000; ++i )
- r += (int)function3();
- e = timer.Elapsed();
- double t3 = e-b;
- b = timer.Elapsed();
- //for( int j=0; j!=10000; ++j )
- for( int i=0; i!=100000; ++i )
- r += (int)function4();
- e = timer.Elapsed();
- double t4 = e-b;
- printf( "%f, %f, %f, %f\n %d\n", t1, t2, t3, t4, r+sideEffect );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement