Banner: ZumGuy Publications and Network

ZumGuy Publications and Network

gnuplot revisited

Posted by Sean on Monday, 6th November 2017 23:40
Here is a more sophisticated example of using
set terminal png size 1920, 1080 enhanced font 'Verdana,15'

# Different log scales
set logscale x 2
set logscale y 10

# %L is the exponent of the current log scale
set format y "%g"
set format x "2e%L"

# Move the legend to the top left
set key top left

# Display grid
set grid

set ylabel "Average Time (s)"
set xlabel "Problem size n"

# Fit the data in output.dat with linear function
# f(x) = a*x + b
# fit f(x) 'output.dat' using 1:2 via a, b

# Arbitrary reference function
g(x) = 4.87882e-11 * x + 1.44652e-07

# Set the number of samples (for discrete point plots)
set sample 50

set output 'plot_insert.png'
set title "Timing stdlib containers: insert"

# Automatically plot multiple columns in the data file,
# use the first row as title, and set the line width to 3
# Finally, also plot reference function in discrete points.
plot for [col=2:6:2] 'output.dat' using 1:col title columnheader lw 3 with lines,
g(x) title "O(n) reference" with points pointtype 1 lw 3

# Plot a second file
set output "plot_erase.png"
set title "Timing stdlib containers: erase"
plot for [col=3:7:2] 'output.dat' using 1:col title columnheader lw 3 with lines,
g(x) title "O(n) reference" with points pointtype 1 lw 3
For reference, here is what the file
looked like in my case:
n	"vector insert"	"vector erase"	"list insert"	"list erase"	"set insert"	"set erase"
16	1.52755e-07	1.49435e-07	9.73663e-08	7.1011e-08	1.68631e-07	9.87532e-08
32	1.51429e-07	1.50084e-07	9.77384e-08	7.05812e-08	1.70701e-07	1.00051e-07
64	1.55609e-07	1.49241e-07	9.77484e-08	7.10019e-08	1.69907e-07	9.99704e-08
128	1.60411e-07	1.54703e-07	9.89177e-08	7.14337e-08	1.71593e-07	1.00082e-07
256	1.66222e-07	1.59109e-07	1.0011e-07	7.30871e-08	1.76871e-07	1.03908e-07
512	1.85162e-07	1.90188e-07	1.04985e-07	7.62717e-08	1.80321e-07	1.05466e-07
1024	2.00222e-07	2.08123e-07	1.08935e-07	7.81612e-08	1.7591e-07	1.02936e-07
2048	2.32146e-07	2.40377e-07	9.63265e-08	6.94104e-08	1.67459e-07	9.7593e-08
4096	3.03668e-07	3.10476e-07	9.53831e-08	6.9201e-08	1.66743e-07	9.74839e-08
8192	4.7185e-07	4.77161e-07	9.79464e-08	7.10629e-08	1.71413e-07	1.00036e-07
16384	1.03076e-06	1.04001e-06	9.42701e-08	6.78754e-08	1.67353e-07	9.81198e-08
32768	2.10713e-06	2.08867e-06	9.5413e-08	6.90011e-08	1.67374e-07	9.85516e-08
65536	4.96184e-06	4.94945e-06	9.63352e-08	6.94543e-08	1.68892e-07	9.87505e-08
131072	1.1501e-05	1.14362e-05	9.45015e-08	6.78938e-08	1.66043e-07	9.72587e-08
262144	2.63044e-05	2.6239e-05	9.56299e-08	6.89657e-08	1.66921e-07	9.77711e-08
524288	5.62351e-05	5.6107e-05	9.64178e-08	6.97338e-08	1.68579e-07	9.83175e-08
1048576	0.000614559	0.00060455	1.01048e-07	7.28126e-08	1.77607e-07	1.03555e-07
And here are the resulting plots:

In this case, I was measuring the time complexity of inserting a single item at the beginning of different
containers, as a function of the current size
has O(n) complexity, whereas
are constant for this operation.

You must be logged in to post messages.