Solved

MSVC compiler optimisations - too extreme or just wrong?

Posted on 2006-11-05
2
217 Views
Last Modified: 2010-04-01
Hi all,

======================================
      #define PI 3.14159265
======================================
      DWORD startTime;
      DWORD endTime;
      DWORD durationTime;
      long number=200000000;

      startTime=GetTickCount();

      double res=0;
      for(long arg=0;arg<number;arg++)
            res=sin(arg*PI/180);

      endTime=GetTickCount();
      durationTime=endTime-startTime;
      char buff[50];
      memset(buff, 0, 50);
      sprintf(buff, "%d", durationTime);
      MessageBox(0, buff, "Duration", 0);
======================================

That program, when running in debug mode takes approx 14,000 ms. However, if I run this in release mode, it takes 0 ms... The time improvements just seem a bit too drastic to be correct, maybe I'm doing something stupid in the code that I haven't realised?

Thanks,
Uni
0
Comment
Question by:Unimatrix_001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 17877103
It might well be the optimizer, since the calculation result in the loop is unused. Try

double* res = new double[number];

     for(long arg=0;arg<number;arg++)
          res[arg]=sin(arg*PI/180);

delete [] res;

to rule that out.
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 17877114
Yep! Thanks for that jkr. Enjoy your points. Clearly my ignorance of compiler optimisations shows though! :S Hehehe,

Thanks again.
Uni
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question