forked from beeware/voc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request beeware#914 from patiences/add-pypy-benchmarks
Add new benchmarks
- Loading branch information
Showing
9 changed files
with
780 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# -*- coding: utf-8 -*- | ||
# The Computer Language Benchmarks Game | ||
# http://shootout.alioth.debian.org/ | ||
# | ||
# contributed by Antoine Pitrou | ||
# modified by Dominique Wahli and Daniel Nanz | ||
|
||
import sys | ||
|
||
|
||
def make_tree(i, d): | ||
|
||
if d > 0: | ||
i2 = i + i | ||
d -= 1 | ||
return (i, make_tree(i2 - 1, d), make_tree(i2, d)) | ||
return (i, None, None) | ||
|
||
|
||
def check_tree(node): | ||
|
||
(i, l, r) = node | ||
if l is None: | ||
return i | ||
else: | ||
return i + check_tree(l) - check_tree(r) | ||
|
||
|
||
def make_check(itde, make=make_tree, check=check_tree): | ||
|
||
i, d = itde | ||
return check(make(i, d)) | ||
|
||
|
||
def get_argchunks(i, d, chunksize=5000): | ||
|
||
assert chunksize % 2 == 0 | ||
chunk = [] | ||
for k in range(1, i + 1): | ||
chunk.extend([(k, d), (-k, d)]) | ||
if len(chunk) == chunksize: | ||
yield chunk | ||
chunk = [] | ||
if len(chunk) > 0: | ||
yield chunk | ||
|
||
|
||
def main(n, min_depth=4): | ||
|
||
max_depth = max(min_depth + 2, n) | ||
stretch_depth = max_depth + 1 | ||
|
||
print('stretch tree of depth %d\t check: %d' % ( | ||
stretch_depth, make_check((0, stretch_depth)))) | ||
|
||
long_lived_tree = make_tree(0, max_depth) | ||
|
||
mmd = max_depth + min_depth | ||
for d in range(min_depth, stretch_depth, 2): | ||
i = 2 ** (mmd - d) | ||
cs = 0 | ||
for argchunk in get_argchunks(i, d): | ||
cs += sum(map(make_check, argchunk)) | ||
print('%d\t trees of depth %d\t check: %d' % (i * 2, d, cs)) | ||
|
||
print('long lived tree of depth %d\t check: %d' % ( | ||
max_depth, check_tree(long_lived_tree))) | ||
|
||
|
||
if __name__ == '__main__': | ||
for i in range(int(sys.argv[1])): | ||
main(int(sys.argv[1])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
#!/usr/bin/env python | ||
|
||
"""Microbenchmark for function call overhead. | ||
This measures simple function calls that are not methods, do not use varargs or | ||
kwargs, and do not use tuple unpacking. | ||
""" | ||
|
||
# Python imports | ||
import time | ||
|
||
|
||
def foo(a, b, c, d): | ||
# 20 calls | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
bar(a, b, c) | ||
|
||
|
||
def bar(a, b, c): | ||
# 20 calls | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
baz(a, b) | ||
|
||
|
||
def baz(a, b): | ||
# 20 calls | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
quux(a) | ||
|
||
|
||
def quux(a): | ||
# 20 calls | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
qux() | ||
|
||
|
||
def qux(): | ||
pass | ||
|
||
|
||
def test_calls(iterations): | ||
times = [] | ||
for _ in range(iterations): | ||
t0 = time.time() | ||
# 40 calls | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
foo(1, 2, 3, 4) | ||
t1 = time.time() | ||
times.append(t1 - t0) | ||
return times | ||
|
||
|
||
if __name__ == "__main__": | ||
# Priming run. | ||
test_calls(1) | ||
|
||
import sys | ||
times = test_calls(int(sys.argv[1])) | ||
|
||
print("Time elapsed: " + str(sum(times))) |
File renamed without changes.
Oops, something went wrong.