I coded a (recursive) function that took way too much time to execute. I was advised to use a "Profiler" so I created this Profiler class to check what operations take too much time.
#pragma once
#include "Timer.h"
#include <string>
#include <iostream>
class Profiler
{
public:
static Profiler& instance() { //singleton.. sorry :P
static Profiler prof;
return prof;
}
void start(const std::string &operationName="") {
_str = " ";
_str += operationName;
_timer.start();
}
void tell() {
if(!_timer.running()) {
std::cout << "Profiler::tell() called when timer wasn't running.\n";
return;
}
std::cout << "It took" << _str << " " << _timer.elapsed() << " ms.\n";
_timer.stop();
}
private:
Profiler() {}
Timer _timer;
std::string _str;
};
The issue is that although my recursive function still runs slow, all the output I get is 0 ms. Am I doing anything wrong? Should I use a more professional Profiler software?