[Scipy-svn] r3569 - in trunk/scipy/sandbox/numexpr: . bench

scipy-svn@scip... scipy-svn@scip...
Fri Nov 23 01:21:58 CST 2007


Author: cookedm
Date: 2007-11-23 01:21:55 -0600 (Fri, 23 Nov 2007)
New Revision: 3569

Added:
   trunk/scipy/sandbox/numexpr/bench/
   trunk/scipy/sandbox/numexpr/bench/boolean_timing.py
   trunk/scipy/sandbox/numexpr/bench/timing.py
Removed:
   trunk/scipy/sandbox/numexpr/boolean_timing.py
   trunk/scipy/sandbox/numexpr/timing.py
Log:
[numexpr] Move timing files to a bench/ subdirectory


Copied: trunk/scipy/sandbox/numexpr/bench/boolean_timing.py (from rev 3568, trunk/scipy/sandbox/numexpr/boolean_timing.py)

Copied: trunk/scipy/sandbox/numexpr/bench/timing.py (from rev 3568, trunk/scipy/sandbox/numexpr/timing.py)

Deleted: trunk/scipy/sandbox/numexpr/boolean_timing.py
===================================================================
--- trunk/scipy/sandbox/numexpr/boolean_timing.py	2007-11-23 07:20:02 UTC (rev 3568)
+++ trunk/scipy/sandbox/numexpr/boolean_timing.py	2007-11-23 07:21:55 UTC (rev 3569)
@@ -1,139 +0,0 @@
-import sys
-import timeit
-import numpy
-
-array_size = 1000*1000
-iterations = 10
-
-numpy_ttime = 0
-numpy_sttime = 0
-numpy_nttime = 0
-numexpr_ttime = 0
-numexpr_sttime = 0
-numexpr_nttime = 0
-
-def compare_times(expr, nexpr):
-    global numpy_ttime
-    global numpy_sttime
-    global numpy_nttime
-    global numexpr_ttime
-    global numexpr_sttime
-    global numexpr_nttime
-
-    print "******************* Expression:", expr
-
-    setup_contiguous = setupNP_contiguous
-    setup_strided = setupNP_strided
-    setup_unaligned = setupNP_unaligned
-
-    numpy_timer = timeit.Timer(expr, setup_contiguous)
-    numpy_time = round(numpy_timer.timeit(number=iterations), 4)
-    numpy_ttime += numpy_time
-    print 'numpy:', numpy_time / iterations
-
-    numpy_timer = timeit.Timer(expr, setup_strided)
-    numpy_stime = round(numpy_timer.timeit(number=iterations), 4)
-    numpy_sttime += numpy_stime
-    print 'numpy strided:', numpy_stime / iterations
-
-    numpy_timer = timeit.Timer(expr, setup_unaligned)
-    numpy_ntime = round(numpy_timer.timeit(number=iterations), 4)
-    numpy_nttime += numpy_ntime
-    print 'numpy unaligned:', numpy_ntime / iterations
-
-    evalexpr = 'evaluate("%s", optimization="aggressive")' % expr
-    numexpr_timer = timeit.Timer(evalexpr, setup_contiguous)
-    numexpr_time = round(numexpr_timer.timeit(number=iterations), 4)
-    numexpr_ttime += numexpr_time
-    print "numexpr:", numexpr_time/iterations,
-    print "Speed-up of numexpr over numpy:", round(numpy_time/numexpr_time, 4)
-
-    evalexpr = 'evaluate("%s", optimization="aggressive")' % expr
-    numexpr_timer = timeit.Timer(evalexpr, setup_strided)
-    numexpr_stime = round(numexpr_timer.timeit(number=iterations), 4)
-    numexpr_sttime += numexpr_stime
-    print "numexpr strided:", numexpr_stime/iterations,
-    print "Speed-up of numexpr strided over numpy:", \
-          round(numpy_stime/numexpr_stime, 4)
-
-    evalexpr = 'evaluate("%s", optimization="aggressive")' % expr
-    numexpr_timer = timeit.Timer(evalexpr, setup_unaligned)
-    numexpr_ntime = round(numexpr_timer.timeit(number=iterations), 4)
-    numexpr_nttime += numexpr_ntime
-    print "numexpr unaligned:", numexpr_ntime/iterations,
-    print "Speed-up of numexpr unaligned over numpy:", \
-          round(numpy_ntime/numexpr_ntime, 4)
-
-
-
-setupNP = """\
-from numpy import arange, where, arctan2, sqrt
-from numpy import rec as records
-from numexpr import evaluate
-
-# Initialize a recarray of 16 MB in size
-r=records.array(None, formats='a%s,i4,f8', shape=%s)
-c1 = r.field('f0')%s
-i2 = r.field('f1')%s
-f3 = r.field('f2')%s
-c1[:] = "a"
-i2[:] = arange(%s)/1000
-f3[:] = i2/2.
-"""
-
-setupNP_contiguous = setupNP % (4, array_size,
-                                ".copy()", ".copy()", ".copy()",
-                                array_size)
-setupNP_strided = setupNP % (4, array_size, "", "", "", array_size)
-setupNP_unaligned = setupNP % (1, array_size, "", "", "", array_size)
-
-
-expressions = []
-expressions.append('i2 > 0')
-expressions.append('i2 < 0')
-expressions.append('i2 < f3')
-expressions.append('i2-10 < f3')
-expressions.append('i2*f3+f3*f3 > i2')
-expressions.append('0.1*i2 > arctan2(i2, f3)')
-expressions.append('i2%2 > 3')
-expressions.append('i2%10 < 4')
-expressions.append('i2**2 + (f3+1)**-2.5 < 3')
-expressions.append('(f3+1)**50 > i2')
-expressions.append('sqrt(i2**2 + f3**2) > 1')
-expressions.append('(i2>2) | ((f3**2>3) & ~(i2*f3<2))')
-
-def compare(expression=False):
-    if expression:
-        compare_times(expression, 1)
-        sys.exit(0)
-    nexpr = 0
-    for expr in expressions:
-        nexpr += 1
-        compare_times(expr, nexpr)
-    print
-
-if __name__ == '__main__':
-
-    print 'Python version:    %s' % sys.version
-    print "NumPy version:     %s" % numpy.__version__
-
-    if len(sys.argv) > 1:
-        expression = sys.argv[1]
-        print "expression-->", expression
-        compare(expression)
-    else:
-        compare()
-
-    print "*************** TOTALS **************************"
-    print "numpy total:", numpy_ttime/iterations
-    print "numpy strided total:", numpy_sttime/iterations
-    print "numpy unaligned total:", numpy_nttime/iterations
-    print "numexpr total:", numexpr_ttime/iterations
-    print "Speed-up of numexpr over numpy:", \
-          round(numpy_ttime/numexpr_ttime, 3)
-    print "numexpr strided total:", numexpr_sttime/iterations
-    print "Speed-up of numexpr strided over numpy:", \
-          round(numpy_sttime/numexpr_sttime, 3)
-    print "numexpr unaligned total:", numexpr_nttime/iterations
-    print "Speed-up of numexpr unaligned over numpy:", \
-          round(numpy_nttime/numexpr_nttime, 3)

Deleted: trunk/scipy/sandbox/numexpr/timing.py
===================================================================
--- trunk/scipy/sandbox/numexpr/timing.py	2007-11-23 07:20:02 UTC (rev 3568)
+++ trunk/scipy/sandbox/numexpr/timing.py	2007-11-23 07:21:55 UTC (rev 3569)
@@ -1,136 +0,0 @@
-import timeit, numpy
-
-array_size = 1e6
-iterations = 10
-
-def compare_times(setup, expr):
-    print "Expression:", expr
-    namespace = {}
-    exec setup in namespace
-
-    numpy_timer = timeit.Timer(expr, setup)
-    numpy_time = numpy_timer.timeit(number=iterations)
-    print 'numpy:', numpy_time / iterations
-
-    try:
-        weave_timer = timeit.Timer('blitz("result=%s")' % expr, setup)
-        weave_time = weave_timer.timeit(number=iterations)
-        print "Weave:", weave_time/iterations
-
-        print "Speed-up of weave over numpy:", numpy_time/weave_time
-    except:
-        print "Skipping weave timing"
-
-    numexpr_timer = timeit.Timer('evaluate("%s", optimization="aggressive")' % expr, setup)
-    numexpr_time = numexpr_timer.timeit(number=iterations)
-    print "numexpr:", numexpr_time/iterations
-
-    print "Speed-up of numexpr over numpy:", numpy_time/numexpr_time
-    return numpy_time/numexpr_time
-
-setup1 = """\
-from numpy import arange
-try: from scipy.weave import blitz
-except: pass
-from numexpr import evaluate
-result = arange(%f)
-b = arange(%f)
-c = arange(%f)
-d = arange(%f)
-e = arange(%f)
-""" % ((array_size,)*5)
-expr1 = 'b*c+d*e'
-
-setup2 = """\
-from numpy import arange
-try: from scipy.weave import blitz
-except: pass
-from numexpr import evaluate
-a = arange(%f)
-b = arange(%f)
-result = arange(%f)
-""" % ((array_size,)*3)
-expr2 = '2*a+3*b'
-
-
-setup3 = """\
-from numpy import arange, sin, cos, sinh
-try: from scipy.weave import blitz
-except: pass
-from numexpr import evaluate
-a = arange(2*%f)[::2]
-b = arange(%f)
-result = arange(%f)
-""" % ((array_size,)*3)
-expr3 = '2*a + (cos(3)+5)*sinh(cos(b))'
-
-
-setup4 = """\
-from numpy import arange, sin, cos, sinh, arctan2
-try: from scipy.weave import blitz
-except: pass
-from numexpr import evaluate
-a = arange(2*%f)[::2]
-b = arange(%f)
-result = arange(%f)
-""" % ((array_size,)*3)
-expr4 = '2*a + arctan2(a, b)'
-
-
-setup5 = """\
-from numpy import arange, sin, cos, sinh, arctan2, sqrt, where
-try: from scipy.weave import blitz
-except: pass
-from numexpr import evaluate
-a = arange(2*%f, dtype=float)[::2]
-b = arange(%f, dtype=float)
-result = arange(%f, dtype=float)
-""" % ((array_size,)*3)
-expr5 = 'where(0.1*a > arctan2(a, b), 2*a, arctan2(a,b))'
-
-expr6 = 'where(a != 0.0, 2, b)'
-
-expr7 = 'where(a-10 != 0.0, a, 2)'
-
-expr8 = 'where(a%2 != 0.0, b+5, 2)'
-
-expr9 = 'where(a%2 != 0.0, 2, b+5)'
-
-expr10 = 'a**2 + (b+1)**-2.5'
-
-expr11 = '(a+1)**50'
-
-expr12 = 'sqrt(a**2 + b**2)'
-
-def compare(check_only=False):
-    total = 0
-    total += compare_times(setup1, expr1)
-    print
-    total += compare_times(setup2, expr2)
-    print
-    total += compare_times(setup3, expr3)
-    print
-    total += compare_times(setup4, expr4)
-    print
-    total += compare_times(setup5, expr6)
-    print
-    total += compare_times(setup5, expr7)
-    print
-    total += compare_times(setup5, expr8)
-    print
-    total += compare_times(setup5, expr9)
-    print
-    total += compare_times(setup5, expr10)
-    print
-    total += compare_times(setup5, expr11)
-    print
-    total += compare_times(setup5, expr12)
-    print
-    print "Average =", total / 11.0
-    return total
-
-if __name__ == '__main__':
-    averages = []
-    for i in range(iterations):
-        averages.append(compare())
-    print "Averages:", ', '.join("%.2f" % x for x in averages)



More information about the Scipy-svn mailing list