amitgoswami7's blog

By amitgoswami7, 6 years ago, In English,

Hi

The code which we submit are being tested on 64bit or 32bit machines ? Does it make any difference in a computationally intensive code if 32 bit or 64 bit is used.

CODE :

#include <ctime>
#include <iostream>
using namespace std;
void test(int end) {
	clock_t startInt = clock();
	int a = 0;
	for (int i = 0; i < end; i++) {
		a++;
	}
	clock_t endInt = clock();
	cout << "int       " << a << " sizeof " << sizeof(int) << " " << (double) (endInt - startInt) / CLOCKS_PER_SEC << endl;

	clock_t startLong = clock();
	long b = 0;
	for (long i = 0; i < end; i++) {
		b++;
	}
	clock_t endLong = clock();
	cout << "long      " << b << " sizeof " << sizeof(long) << " " << (double) (endLong - startLong) / CLOCKS_PER_SEC << endl;

	clock_t startLongLong = clock();
	long long c = 0;
	for (long long i = 0; i < end; i++) {
		c++;
	}
	clock_t endLongLong = clock();
	cout << "long long " << c << " sizeof " << sizeof(long long) << " " << (double) (endLongLong - startLongLong) / CLOCKS_PER_SEC << endl;
}

int main() {
	test(2147483647);
	test(1000000);
}


int 2147483647 sizeof 4 11.965 long 2147483647 sizeof 4 11.716 long long 2147483647 sizeof 8 27.238 int 1000000 sizeof 4 0.015 long 1000000 sizeof 4 0 long long 1000000 sizeof 8 0.016

USING 32 BIT VISTA C++ ECLIPSE CDT WITH CYGWIN

 
 
 
 
  • Vote: I like it
  • +5
  • Vote: I do not like it

»
6 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Are you sure that compiler produce any machine code for

 for (long long i = 0; i < 1000000; i++);

15 ms for long can be just time measurement bias