Dears! I've got stuck on how to measure the number of executed basic operations(commands) per 1 second which can be done on the various data types(here is int, char, long, double). Function gettime(double time) should measure the time when the operation is started and the time when the operation is ended and return the calculated value in type double. Return type of gettime() function is not void!
Here is a code template, language C++
#include <iostream>
#include <chrono> // to measure time which is taken to perform the operation
using namespace std;
using namespace std::chrono;
double gettime(double time) // function to control start time and end time simultaneously
{
return time = chrono::high_resolution_clock::now();
}
int main(int argc, const char *argv[])
{
char operation;
switch(operation) // we need to estimate the time to all operations separately
{
case '+': gettime(startTime1)/* Something is required to put here */ gettime(endTime1) break; // basic operation +
case '-': gettime(startTime2) /* Something is required to put here */ gettime(endTime2) break; // basic operation -
case '*': gettime(startTime3)/* Something is required to put here */ gettime(endTime3) break; // basic operation *
case '/': gettime(startTime4) /* Something is required to put here */ gettime(endTime4) break; // basic operation /
}
cin.get();
return 0;
}
In switch operator I measure the amount of time which is required to perform the operation on the computer system separately by using case keyword and there I call the function gettime(double time) to measure the time which the operation took while executing. The question about the double gettime(double time) function: "What I need to use in this function to calculate the amount of time which was taken by the operation, is it better to use time_t variable for instance and then convert it to type double or I need to use some variables or functions from <chrono> header file? And what return type must have function gettime() to return current time value. Is the return type double is correct here or it is better to use another one?"
Next step:
There's required to store the amount of operation per 1 second in some variable, and increase the value of this variable in for loop. Also I need calculate the speed of the performance which is measured in %. What function(s) should be implemented in order to get the required result? We take the fastest operation for 100%
The example of the expected output
Operation Type Number of operations Effectiveness
+ int 7.825654е07 100%
- int 7.710049е07 100%
* int 3.469522e07 45%
/ int 6.168039e06 8%
+ long 3.706285е07 49%
- long 3.701185е07 49%
* long 1.667828е07
.... ...... ........... ....
/ double 4.094732e06 5%
Hope I created a clear picture of the problem. If something is missing, write, I will add more details :)