# measure renderer performance, writing to log file

def testTimeSpectrogram():
    ds= getDataSet('file:///home/jbf/ct/hudson/data/cdf/CSA_Download_20140430_1317/C3_CP_PEA_PITCH_FULL_DPFlux/C3_CP_PEA_PITCH_FULL_DPFlux__20020430_065000_20020430_151000_V111128.cdf?Data_LEEA__C3_CP_PEA_PITCH_FULL_DPFlux')
    plot( ds )
    
    from java.lang.System import currentTimeMillis as ctm
    
    avg= 0.
    navg= 0
    for i in xrange(10):
        t0= ctm()
        dom.plots[0].xaxis.range= dom.plots[0].xaxis.range.rescale( -0.01, 0.99 )
        waitUntilIdle()
        t= ctm()-t0
        avg=avg + t
        navg= navg+ 1
        
    for i in xrange(10):
        t0= ctm()
        dom.plots[0].xaxis.range= dom.plots[0].xaxis.range.rescale( 0.01, 1.01 )
        waitUntilIdle()
        t= ctm()-t0
        avg=avg + t
        navg= navg+ 1
    return 1.*avg/navg

def testSliceSpectrogram():
    ds= getDataSet('file:///home/jbf/ct/hudson/data/cdf/CSA_Download_20140430_1317/C3_CP_PEA_PITCH_FULL_DPFlux/C3_CP_PEA_PITCH_FULL_DPFlux__20020430_065000_20020430_151000_V111128.cdf?Data_LEEA__C3_CP_PEA_PITCH_FULL_DPFlux')
    plot( ds )
    
    from java.lang.System import currentTimeMillis as ctm
    
    avg= 0.
    navg= 0
    for i in xrange(12):
        t0= ctm()
        dom.plotElements[0].component= "|slices(':',1,%d,':')" % i
        waitUntilIdle()
        t= ctm()-t0
        avg=avg + t
        navg= navg+ 1
        
    for i in xrange(10):
        t0= ctm()
        dom.plotElements[0].component= "|slices(':',1,%d,':')" % (9-i)
        waitUntilIdle()
        t= ctm()-t0
        avg=avg + t
        navg= navg+ 1
        
    return 1.*avg/navg

def testTimeSeries():
    ds= getDataSet('file:///home/jbf/ct/hudson/data/cdf/CSA_Download_20140430_1317/C3_CP_PEA_PITCH_FULL_DPFlux/C3_CP_PEA_PITCH_FULL_DPFlux__20020430_065000_20020430_151000_V111128.cdf?Data_LEEA__C3_CP_PEA_PITCH_FULL_DPFlux')
    plot( ds )
    
    dom.plotElements[0].component= "|slices(':',1,':',22)" 
    from java.lang.System import currentTimeMillis as ctm
    
    from org.autoplot import RenderType
    dom.plotElements[0].renderType= RenderType.series
    waitUntilIdle()
    
    avg= 0.
    navg= 0
    for i in xrange(10):
        t0= ctm()
        dom.plots[0].xaxis.range= dom.plots[0].xaxis.range.rescale( -0.01, 0.99 )
        waitUntilIdle()
        t= ctm()-t0
        avg=avg + t
        navg= navg+ 1
        
    for i in xrange(10):
        t0= ctm()
        dom.plots[0].xaxis.range= dom.plots[0].xaxis.range.rescale( 0.01, 1.01 )
        waitUntilIdle()
        t= ctm()-t0
        avg=avg + t
        navg= navg+ 1
    return 1.*avg/navg

t= TimeUtil.now()
t1= testTimeSpectrogram()
t2= testSliceSpectrogram()
t3= testTimeSeries()

f= open( '/home/jbf/ct/hudson/log/renderPerformance.dat', "a" )
f.write( '%s,%.1f,%.1f,%.1f\n' % ( t, t1,t2,t3 ) )
f.close()