Benchmarking applications in a fully loaded machine

I need a “time” or compare the number of a crunchy application written in C / C ++. The problem is that the machine on which I run the program is usually full of people who do such things, so the processors are always at full load.

I was thinking about using functions from time.h liket "get time of day" (I don’t remember the exact syntax, sorry) and analogies, but I'm afraid that they will not be good for this case, I'm right

And the bash time program gave me some errors a long time ago.

Also the problem is that sometimes I need to get timings in the range of 0.5 seconds, etc.

Does anyone have a clue?

PS: the compiler is gcc, and in some cases nvcc (NVIDIA) PS2: in my tests, I just want to measure the runtime between the two parts of the main function

+3
source share
3 answers

From your other recent questions, you seem to be using MPI for parallelization. Assuming this question is in the same context , then the easiest way would be to use your MPI_Wtime () application .

On the man page:

. - . . , .

:

#include "mpi.h"

int main(int argc, char **argv)
{
    int rc, taskid;
    double t_start, t_end;

    MPI_Init(&argc,&argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&taskid); 

    t_start = MPI_Wtime();

    /* .... your computation kernel .... */

    t_end = MPI_Wtime();

    /* make sure all processes have completed */
    MPI_Barrier(MPI_COMM_WORLD);

    if (taskid == 0) {
        printf("Elapsed time: %1.2f seconds\n", t_start - t_end);
    }

    MPI_Finalize();
    return 0;
} 

, MPI , MPI_Wtick() , .

+1

, , GNU g++ -pg .

, , , gprof, .

.

+2

, . .

, bash (/usr/bin/time), , , , , - .

:

#include <ctime>
#include <iostream>

struct Timer {
  std::clock_t _start, _stop;
  Timer() : _start(std::clock()) {}
  void restart() { _start = std::clock(); }
  void stop() { _stop = std::clock(); }
  std::clock_t clocks() const { return _stop - _start; }
  double secs() const { return double(clocks()) / CLOCKS_PER_SEC; }
};

int main() {
  Timer t;
  //run_some_code();
  t.stop();
  std::cout << "That took " << t.secs() << " seconds.\n";
  return 0;
}
+1

Source: https://habr.com/ru/post/1790413/


All Articles