954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Ideas for Testing Performance of Datatypes for MS Science Project

Hello,

I am looking into testing the performance of different numerical datatypes like double, integer, float, etc and see which one is the fastest. Is there a way to do this in C++. Time the time it takes to do basic arithmetic with numbers. Starting and end a timer within a function? Would this be easier in another languages? I am 13. Also what data types would you recommend testing? Thanks and any suggestion would be greatly appreciated!

matthewkeating
Light Poster
28 posts since Jan 2011
Reputation Points: 10
Solved Threads: 2
 

I will tell you int's will be faster than floats/doubles. And doubles will be faster than floats. But to answer your question yes, you can use ctime header. Here is an example:

#include <iostream>
#include <ctime>

int main(){
  time_t startTime = clock();
   /* code to test goes here */
  time_t endTime = clock();

  cout << "Difference in time(milliseconds) : " << endTime - startTime << endl;
}
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 

Thank you soo much! Do you have any recommendations for what types are math I should do? What opearations would be most common for programmers to use in their projects?

matthewkeating
Light Poster
28 posts since Jan 2011
Reputation Points: 10
Solved Threads: 2
 

I guess you can try the standard functions like sin or cos or tan or sqrt and so on.
If you looking to win the fair/project then you might want to think of something else because comparing operations aren't so valuable or useful.

firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: