Best way to compare two identical parallel programs

I have two identical purpose programs made in C++ and i need to compare the total execution time, total CPU usage, total memory usage, execution time at instruction level, etc. The main difference between the two programs are that the first is made using threads and the second using processes. The proposal is simply run N threads or processes and wait them to stop.

I already used -pg option in the g++ compiler but the program that uses processes created many gmon.out files, one per process. I think the correct way to do this is by adding some instructions to my code to measure time, etc.

Anyone can help me?
you should run both through a good profiler. There are tools to do what you want already. I don't know the go-to for unix, visual studio has one built in.

you can do it yourself, but its going to be a big pain.
Last edited on
Thank you for the answer! My code is only compatible with Linux environment, I would like a profiller that runs on it. Someone knows?
I created this to explore the idea.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <thread>
#include <string>

#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

void worker() {
  for ( int i = 0 ; i < 10 ; i++ ) {
    std::cout << "worker = " << i << std::endl;
  }
}

int main ( int argc, char *argv[] ) {
  if ( argc > 1 ) {
    std::cout << "Starting" << std::endl;
    if ( std::string(argv[1]) == "thread" ) {
      std::thread t (worker);
      t.join();
    } else
    if ( std::string(argv[1]) == "process" ) {
      if ( fork() == 0 ) {
        execlp(argv[0],argv[0],(const char*)NULL);
      } else {
        int status;
        waitpid(-1, &status, 0);
      }
    }
    std::cout << "Completed" << std::endl;
  } else {
    // Do the work when spawned as a child process
    worker();
  }
}


Then looked at the results of

strace -f -C -tt ./a.out process
strace -f -C -tt ./a.out thread
/usr/bin/time -v ./a.out process
/usr/bin/time -v ./a.out thread

strace has a lot of options for filtering the information it traces, and redirecting the trace output to file(s).
Topic archived. No new replies allowed.