To use library copy sfpl.cpp, sfpl.hpp and font.cpp inside your project and feed them to the compiler.
P.S. It is better not to open font.cpp :-)
#include "sfpl.hpp"
using namespace sfpl;
int main(){
// Instead of regular array any array-like data structure can be used
// including std::vector, std::array and others
double x[] = {0, 1, 2, 3, 4, 5};
double y[] = {0, 1, 4, 9, 16, 25};
DataSource source;
source.X = &x[0]; // pointer to the first element of X array
source.Y = &y[0]; // pointer to the first element of Y array
source.Count = 6; // elements count of X and Y arrays
PlotBuilder::Build(source, "parabola.jpg");
}
DataSource sources[SIZE];
//... code to fill traces array
PlotBuilder::Build(sources, "parabola.jpg");
DataSource source;
//... code to fill trace structure
source.Name = "Source Name";
By default they are empty.
//...
OutputParameters params;
params.ImageWidth = 1280;
params.ImageHeight = 720;
params.PlotTitle = "PlotTitle";
params.XAxisName = "XAxisName";
params.YAxisName = "YAxisName";
PlotBuilder::Build(source, "parabola.jpg", params);
It can be done somehow like this
#include "sfpl.hpp"
// https://github.com/BloodRedTape/clock
#include "clock.hpp"
using namespace sfpl;
void HeavyOperation(int n){
++n;
for(int i = 0; i<n; i++){
char *array = new char[n*20];
for(int j = 0; j<n*20; j++)
array[j] = 0;
delete[] array;
}
}
int main(){
const int BenchmarkSize = 1000;
double x[BenchmarkSize];
double y[BenchmarkSize];
for(int j = 0; j<BenchmarkSize; ++j){
Clock clock;
HeavyOperation(j);
auto time = clock.GetElapsedTime().AsNanoseconds();
x[j] = j;
y[j] = time;
}
OutputParameters params;
params.ImageWidth = 1280;
params.ImageHeight = 720;
params.PlotTitle = "Heavy Operation Test";
params.XAxisName = "Heavy operation size";
params.YAxisName = "Time [ns]";
DataSource source;
source.X = &x[0];
source.Y = &y[0];
source.Count = BenchmarkSize;
PlotBuilder::Build(source, "heavy_test.jpg", params);
}
Or in case you are a big STL fan
#include <vector>
#include "sfpl.hpp"
// https://github.com/BloodRedTape/clock
#include "clock.hpp"
using namespace sfpl;
void HeavyOperation(int n){
++n;
for(int i = 0; i<n; i++){
char *array = new char[n*20];
for(int j = 0; j<n*20; j++)
array[j] = 0;
delete[] array;
}
}
int main(){
std::vector<double> x;
std::vector<double> y;
for(int j = 0; j<1000; ++j){
Clock clock;
HeavyOperation(j);
auto time = clock.GetElapsedTime().AsNanoseconds();
x.push_back(j);
y.push_back(time);
}
OutputParameters params;
params.ImageWidth = 1280;
params.ImageHeight = 720;
params.PlotTitle = "Heavy Operation Test";
params.XAxisName = "Heavy operation size";
params.YAxisName = "Time [ns]";
DataSource source;
source.X = &x[0];
source.Y = &y[0];
source.Count = x.size();
PlotBuilder::Build(source, "heavy_test.jpg", params);
}


