Skip to content

Commit

Permalink
plot_test.cc tests performance
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuo committed Jan 31, 2015
1 parent 58fa73c commit 9a65a49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion examples/procmon/plot_test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "plot.h"
#include <muduo/base/Timestamp.h>
#include <vector>
#include <math.h>
#include <stdio.h>
Expand All @@ -8,10 +9,18 @@ int main()
std::vector<double> cpu_usage;
for (int i = 0; i < 300; ++i)
cpu_usage.push_back(1.0 + sin(pow(i / 30.0, 2)));
Plot plot(600, 100, 600, 2);
Plot plot(640, 100, 600, 2);
muduo::Timestamp start(muduo::Timestamp::now());
const int N = 10000;
for (int i = 0; i < N; ++i)
muduo::string png = plot.plotCpu(cpu_usage);
double elapsed = timeDifference(muduo::Timestamp::now(), start);
printf("%d plots in %f seconds, %f PNG per second, %f ms per PNG\n",
N, elapsed, N / elapsed, elapsed * 1000 / N);
muduo::string png = plot.plotCpu(cpu_usage);

FILE* fp = fopen("test.png", "wb");
fwrite(png.data(), 1, png.size(), fp);
fclose(fp);
printf("Image saved to test.png\n");
}
1 change: 1 addition & 0 deletions examples/procmon/procmon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ class Procmon : boost::noncopyable
Buffer response_;
};

// define outline for __attribute__
int Procmon::appendResponse(const char* fmt, ...)
{
char buf[1024];
Expand Down

0 comments on commit 9a65a49

Please sign in to comment.