0

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!

Edited by matthewkeating: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by firstPerson
1

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;
}
Votes + Comments
Thank you! Awesome answer.
0

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?

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.