C++ compilers tend to optimize the code like you posted entirely out so i somewhat modified it to give any usage to the variables there... and also to measure the time directly in code. Somehow i get here different results than you. Maybe i just know C# not well enough and do something wrong with it. Other possibilities are that you run not "C++" but "managed C++" or that you run "Debug" version of C++. On that case your computer seems about 4 times better than mine.
//C# code
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DateTime time1 = DateTime.Now;
double d1 = 0.727272;
double d2 = 0.26252;
double d3 = 343432.232;
for (int i = 0; i < 100000000; i++)
{
d3 = d1 * d2;
d1 = d3 * d2;
d2 = d2 * d2;
d3 = d1 * d2;
d3 = d3 * d2;
}
DateTime time2 = DateTime.Now;
TimeSpan span = time2 - time1;
Console.WriteLine("{0};{1};{2};{3}",span, d1,d2,d3);
}
}
}
Displays:
00:00:02.1089395;0;0;0
I get it means 2109 milliseconds?
//C++ code
#include "stdafx.h"
#include <sys/timeb.h>
#include <sys/types.h>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
timeb time1;
ftime(&time1);
double d1 = 0.727272;
double d2 = 0.26252;
double d3 = 343432.232;
for (int i = 0; i < 100000000; i++)
{
d3 = d1 * d2;
d1 = d3 * d2;
d2 = d2 * d2;
d3 = d1 * d2;
d3 = d3 * d2;
}
timeb time2;
ftime(&time2);
std::cout << (time2.time - time1.time)*1000 + time2.millitm - time1.millitm
<< ";" << d1 << ";" << d2 << ";" << d3 << "\n";
char c;
std::cin >> c;
return 0;
}
Displays:
594;0;0;0
C++ runs bit less than 4 times quicker but not much.
Both examples were compiled with very same Visual Studio 2005 Professional.