# example to illustrate slowdown in vtkPiecewiseFunction::GetValue() call
# on my 1.6 GHz Pentium-M on Windows XP with VS 7.1, I get:
# 0.40 seconds per 65536 GetValue() calls on VTK CVS 2004/07/14
# 2.42 seconds per 65536 GetValue() calls on VTK CVS 2004/11/20
# I.e. a slow-down of more than 6 times!

# It *looks* like this could be due to the Update() call (and its associated
# overhead) that gets called in vtkPiecewiseFunction::GetValue()

import vtk
import random
import time

otf = vtk.vtkPiecewiseFunction()
otf.AddPoint(0.0, 0.0)
otf.AddPoint(253.9, 0.0)
otf.AddPoint(254, 0.95)
otf.AddPoint(255, 0.95)

numLoops = 10
startTime = time.time()
for i in range(numLoops):
    for k in xrange(65536):
        otf.GetValue(random.randint(0,255))

endTime = time.time()

loopTime = (endTime - startTime) / float(numLoops)
print "%f seconds per loop of 65536 GetValue() calls." % (loopTime,)
