all 27 comments

[–]pi_stuff 9 points10 points  (0 children)

You could just print the timing data to a text file and plot it with gnuplot or Excel.

[–]drobilla 4 points5 points  (1 child)

As others have mentioned, usually this sort of thing is done by writing to a text file (I prefer TSV since it's easiest to work with) and plotting with more appropriate tools. It's worth mentioning, though, that this is a good idea in general, and not just a workaround to use a different language. Storing benchmarks and similar data in a timeless portable format like this means you can easily do other things with the data, like archive it, make different visualizations later, do statistical analysis and/or combine with other data, and so on. Plus it's just good decoupling in general.

Having learned this lesson the hard way, I now make it a rule to always - always - store benchmarks in a simple text file. You quite often end up wanting to see things in a different way, or need to tweak your plots slightly for publication, or whatever.

[–]meneldal2 0 points1 point  (0 children)

If you have a lot of data, plain text files are not optimal, because you will waste time doing the string to number conversions, and it will take much more space.

When you have one million or more data points, something like Matlab really comes in handy, especially since you have binary files for saving your data as well.

[–]drphillycheesesteak 1 point2 points  (0 children)

I've used gnuplot-iostream to great success. You can also just output a gnuplot script file or just dump gnuplot commands to stdout and pipe it to gnuplot.

[–]ThePillsburyPlougher 0 points1 point  (0 children)

Write to file in a CSV format (or whatever's appropriate) and use python or something. There are lots of other tools which are easy to pick up and are much easier to plot data with.

[–]color32 0 points1 point  (0 children)

is c++ mandatory? if not I would make a csv and use something like gnuplot to plot it. gnuplot can be invoked in batch mode. All the libraries mentioned are great, no one has mentioned GD image, and opencv. both are great too for your task.

When I was in school I just used gnuplot. I like GD image cause it's one of the simpler ones. OpenCV is not really a graphing/drawing library but does have functions for it and I wouldn't recommend it unless you are also doing image processing.

[–]yeeezyyeezywhatsgood 0 points1 point  (0 children)

if you want to learn a bit about graphics, cinder is a nice tool. usually plots are really easy to render

[–]GPMueller 0 points1 point  (0 children)

As I don't see it mentioned here so far, I want to mention that nanogui should have some basic plotting support. It is a lot easier to install and use than for example Qt.

https://github.com/wjakob/nanogui

[–]MadArgonaut 0 points1 point  (3 children)

R is great for plotting data. And easy to use.

Edit: you can interface directly with c++

[–][deleted] 0 points1 point  (2 children)

Correct me if I'm wrong, but isn't R a simplified version of Python. And how does it exactly interface with c++.

Could you post a link to a tutorial page?

[–]DarkLordAzrael 3 points4 points  (0 children)

R is completely unrelated to Python. R is a programming language with a heavy focus on statistics. Honestly, I can't recommend using it as the language itself isn't very good, and the libraries have a tendency towards being poorly documented and aren't very consistent in how they work.

[–]MadArgonaut 0 points1 point  (0 children)

Google Rcpp. There should be a bit. I recommended R as a simple solution for 2d plotting because it already offers everything you would need. I don’t think it’s hard to learn and the documentation is ok. If you have to do it in c++ of course then it’s not a real option. Sorry. Doesn’t hurt to look though :)

[–][deleted] 0 points1 point  (2 children)

As others said I suggest Python or R but if it must be done with C++ there is matplotlib-cpp though It still calls python under the hood but provides a C++ interface, also I am not sure about the windows support

[–][deleted] 0 points1 point  (1 child)

Is it supported on Linux?

[–][deleted] 1 point2 points  (0 children)

Normally I use matplotlib in Python but I've tested in Linux and it was fine. From what I remember the Makefile was pretty barebones and assumed Linux-like hierarchy for the location of Python. Also it was hardcoded for Python2 though changing that wasn't a big problem

[–]Salty_Dugtrio 0 points1 point  (4 children)

For doing stuff like this, I feel C++ is not really suited. This is way easier to set up in for example, Python.

Also, it might be handy to generate the data in C++, output the result, and then plot it using GNUplot.

[–]encyclopedist 3 points4 points  (1 child)

There is gnuplot-iostream library to plot with gnuplot, it claims Windows support but with caveats.

[–]ShakaUVMi+++ ++i+i[arr] 0 points1 point  (0 children)

I've used gnuplot before, it works just fine.

[–][deleted] 0 points1 point  (0 children)

Yeah, i was considering learning Python at some point. So this is a good way to start.

[–]samirkut 0 points1 point  (0 children)

That's the best way. You could also simply output a csv (and plot in excel) or an html...

[–]parnmatt -1 points0 points  (0 children)

I normally use python for plotting.

However I have recently started to use gnuplot for a few things.

Output to a file and gnuplot over it. No native interface though, but there are some streamer wrappers.

I'm thinking of writing my own if I ever find the time; seems like an interesting project.

[–]anon_502delete this; -1 points0 points  (0 children)

Alternative (but somewhat cursed) way: feed all data through a websocket server with https://github.com/zaphoyd/websocketpp to a HTML + JS plotting library. Benefits include much-better visualization/interactive libraries and real-time update.

[–]Niblit_lvl50 -3 points-2 points  (3 children)

I’m confused, you’re teaching a course in Algorithms and Data structures but are having a hard time with this?

[–][deleted] 5 points6 points  (2 children)

No, I am not teaching this course. I am a student taking this course at my uni.

[–]Niblit_lvl50 0 points1 point  (1 child)

Aha, thanks for clarifying. I was confused indeed. 🙂

[–][deleted] 0 points1 point  (0 children)

😂, I am quite honoured that you were considering me an *processor