#!/bin/bash

######################################################
#
# Speed test of RRD::Editor 
#
######################################################

numupdates=2500

start=920804399
# NB: Its a good idea to use /usr/bin/speedy rather than /usr/bin/perl in the shebang for rrdtool.pl when calling rrdtool.pl inside a loop, as is done here.
# That way, the cost of perl compiling rrdtool.pl is only incurred once.
./rrdtool.pl create test2.rrd --start $start DS:el1:COUNTER:600:U:U DS:el2:GAUGE:600:U:U RRA:AVERAGE:0.5:1:288  RRA:AVERAGE:0.5:6:336 RRA:AVERAGE:0.5:24:372 RRA:AVERAGE:0.5:288:366

tstart=`date +%s%N`
j=$(($start+1-300))
for i in $(seq 1 1 $numupdates) ; do 
j=$(($j+300)) 
./rrdtool.pl update test2.rrd $j:1:2
done
tstop=`date +%s%N`
echo "RRD::Editor" $(( ($tstop-$tstart)/1000000 ))

rrdtool create test.rrd --start $start DS:el1:COUNTER:600:U:U DS:el2:GAUGE:600:U:U RRA:AVERAGE:0.5:1:288  RRA:AVERAGE:0.5:6:336 RRA:AVERAGE:0.5:24:372 RRA:AVERAGE:0.5:288:366
tstart=`date +%s%N`
j=$(($start+1-300))
for i in $(seq 1 1 $numupdates) ; do
j=$(($j+300))
rrdtool update test.rrd $j:1:2
done
tstop=`date +%s%N`
echo "RRDTOOL" $(( ($tstop-$tstart)/1000000 ))

