From cbdc42af021f898e82d3e78ce7c636d3fb5eece0 Mon Sep 17 00:00:00 2001 From: Russell Date: Mon, 10 Jan 2011 12:21:19 -0500 Subject: Some performance improvements. Faster evaluation of range-based queries with lambda expressions. Faster exp with approximated fastexp. Some changes to the component registry. --- TestProfile.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'TestProfile.py') diff --git a/TestProfile.py b/TestProfile.py index 342def6..663e57b 100644 --- a/TestProfile.py +++ b/TestProfile.py @@ -1,8 +1,9 @@ -#import cProfile +import cProfile import struct import random +import math #from LightInstallation import main -numiter = 10000000 +numiter = 1000000 def main1(): for i in xrange(0,numiter): if 'abc' == 'def': @@ -37,14 +38,27 @@ def dictlookup(): lookup[i] = struct.pack('B', random.randint(0,255)) for i in xrange(0,numiter): b = lookup[random.randint(0,255)] -print('starting') -abc1() -print('starting') -abc2() -print('done') -#command = """abc1()""" -#cProfile.runctx(command, globals(), locals()) +def dist1(): + l1 = [21.43, 5423.123] + l2 = [123, 12312345] + for i in xrange(0,numiter): + d = math.sqrt(sum([(l1[i]-l2[i])**2 for i in range(len(l1))])) +def dist2(): + l1 = [21.43, 5423.123] + l2 = [123, 12312345] + for i in xrange(0,numiter): + d = math.sqrt((l1[0]-l2[0])**2+(l1[1]-l2[1])**2) +def exptest(): + for i in xrange(0, numiter): + a = math.exp(-1) + print a +def expapprox(): + for i in xrange(0, numiter): + a = 1+-1+(-1)**2/float(2) + print a +command = """exptest()""" +cProfile.runctx(command, globals(), locals()) -#command = """abc2()""" -#cProfile.runctx(command, globals(), locals()) +command = """expapprox()""" +cProfile.runctx(command, globals(), locals()) -- cgit v1.2.3