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!

Recommended Answers

All 3 Replies

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;
}
commented: Thank you! Awesome answer. +1

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.