# HG changeset patch # User paulb@localhost.localdomain # Date 1165015426 -3600 # Node ID a22ab9008cb84815d46905aa90fde2b77b3666d9 # Parent 3e63ed6f2d740e049b27e3dcc9d3b78db1d39f98 Added some benchmarks from the Computer Language Shootout: http://shootout.alioth.debian.org/ diff -r 3e63ed6f2d74 -r a22ab9008cb8 tests/shootout/LICENCE.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/shootout/LICENCE.txt Sat Dec 02 00:23:46 2006 +0100 @@ -0,0 +1,27 @@ +Copyright © 2004,2005,2006 Brent Fulgham + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of "The Computer Language Shootout Benchmarks" nor the + name of "Computer Language Shootout" nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff -r 3e63ed6f2d74 -r a22ab9008cb8 tests/shootout/binary-trees.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/shootout/binary-trees.py Sat Dec 02 00:23:46 2006 +0100 @@ -0,0 +1,44 @@ +# The Computer Language Shootout Benchmarks +# http://shootout.alioth.debian.org/ +# +# contributed by Antoine Pitrou +# modified by Dominique Wahli + +from sys import argv + +def make_tree(item, depth): + if depth > 0: + item2 = 2 * item + depth -= 1 + return (item, make_tree(item2 - 1, depth), make_tree(item2, depth)) + else: + return (item, None, None) + +def check_tree((item, left, right)): + if left is not None: + return item + check_tree(left) - check_tree(right) + else: + return item + +def main(): + min_depth = 4 + max_depth = max(min_depth + 2, int(argv[1])) + stretch_depth = max_depth + 1 + + print "stretch tree of depth %d\t check: %d" % (stretch_depth, check_tree(make_tree(0, stretch_depth))) + + long_lived_tree = make_tree(0, max_depth) + + for depth in xrange(min_depth, stretch_depth, 2): + iterations = 2**(max_depth - depth + min_depth) + + check = 0 + for i in xrange(1, iterations + 1): + check += check_tree(make_tree(i, depth)) + check_tree(make_tree(-i, depth)) + + print "%d\t trees of depth %d\t check: %d" % (iterations * 2, depth, check) + + print "long lived tree of depth %d\t check: %d" % (max_depth, check_tree(long_lived_tree)) + +if __name__ == '__main__': + main()