Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <conio.h>
- using namespace std;
- void test_int()
- {
- int res = 0;
- for( size_t i = 0; i < 30000000; i++ ) {
- res += rand() / (rand() + 1);
- }
- cout << res << endl;
- }
- void test_int64()
- {
- __int64 res = 0;
- for( size_t i = 0; i < 30000000; i++ ) {
- res += rand() / (rand() + 1);
- }
- cout << res << endl;
- }
- void test_float()
- {
- float res = 0.0f;
- for( size_t i = 0; i < 30000000; i++ ) {
- res += rand() / (rand() + 1);
- }
- cout << res << endl;
- }
- void test_rand()
- {
- int res = 0;
- for( size_t i = 0; i < 30000000; i++ ) {
- res += rand() / (rand() + 1);
- }
- cout << res << endl;
- }
- void test_double()
- {
- double res = 0.0;
- for( size_t i = 0; i < 30000000; i++ ) {
- res += rand() / (rand() + 1);
- }
- cout << res << endl;
- }
- int main(int argc, char* argv[])
- {
- srand( time( NULL ) );
- clock_t start;
- start = clock();
- test_rand();
- cout << "Rand: " << clock() - start << " tics" << endl;
- start = clock();
- test_int();
- cout << "Int: " << clock() - start << " tics" << endl;
- start = clock();
- test_int64();
- cout << "Int64: " << clock() - start << " tics" << endl;
- start = clock();
- test_float();
- cout << "Float: " << clock() - start << " tics" << endl;
- start = clock();
- test_double();
- cout << "Double: " << clock() - start << " tics" << endl;
- cout << "Press any key to quit." << endl;
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement