本文整理汇总了Python中benchmark.Benchmark.measure方法的典型用法代码示例。如果您正苦于以下问题:Python Benchmark.measure方法的具体用法?Python Benchmark.measure怎么用?Python Benchmark.measure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类benchmark.Benchmark
的用法示例。
在下文中一共展示了Benchmark.measure方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: s
# 需要导入模块: from benchmark import Benchmark [as 别名]
# 或者: from benchmark.Benchmark import measure [as 别名]
import helper
helper.load_backends()
code = """
(begin
(define (grow)
(set! s (string-append "123" s "456" s "789"))
(set! s (string-append
(substring s (quotient (string-length s) 2) (string-length s))
(substring s 0 (+ 1 (quotient (string-length s) 2)))))
s)
(define (trial n)
(do ((i 0 (+ i 1)))
((> (string-length s) n) (string-length s))
(grow))))
"""
def call_trial(vm):
vm.eval(vm.compile('(define s "abcdef")'))
scm = vm.eval(vm.compile('(trial 1000000)'))
assert vm.fromscheme(scm) == 1048566
bm = Benchmark(title="string-append and substring performance", repeat=10)
for backend in helper.BACKENDS:
vm = helper.VM(backend=backend)
vm.eval(vm.compile(code))
bm.measure(backend, call_trial, vm)
helper.report(bm.report())
示例2: load_backend
# 需要导入模块: from benchmark import Benchmark [as 别名]
# 或者: from benchmark.Benchmark import measure [as 别名]
"""\
This benchmark test the loading time of each backend.
But it seems to be hard to make this benchmark accurate. Because
it is only slow for the first time when a VM is to be loaded. Later
it will be very fast since all related stuffs are already in memory.
So repeating here just makes no help.
"""
from benchmark import Benchmark
import helper
def load_backend(backend):
vm = helper.VM(backend=backend)
bm = Benchmark(title="Time to load the VM", repeat=1)
for backend in helper.BACKENDS:
bm.measure(backend, load_backend, backend)
helper.report(bm.report())
示例3: call_sum
# 需要导入模块: from benchmark import Benchmark [as 别名]
# 或者: from benchmark.Benchmark import measure [as 别名]
from benchmark import Benchmark
import helper
helper.load_backends()
code = """
(lambda (n)
(define (iter sum i)
(if (= i 0)
sum
(iter (+ sum i)
(- i 1))))
(iter 0 n))
"""
def call_sum(proc, vm):
scm = vm.apply(proc, [vm.toscheme(10000)])
assert vm.fromscheme(scm) == 50005000
bm = Benchmark(title="Tail call performance", repeat=10)
for backend in helper.BACKENDS:
vm = helper.VM(backend=backend)
proc = vm.eval(vm.compile(code))
bm.measure(backend, call_sum, proc, vm)
helper.report(bm.report())
示例4: call_tak
# 需要导入模块: from benchmark import Benchmark [as 别名]
# 或者: from benchmark.Benchmark import measure [as 别名]
from benchmark import Benchmark
import helper
helper.load_backends()
code = """
(define (tak x y z)
(if (not (< y x))
z
(tak (tak (- x 1) y z)
(tak (- y 1) z x)
(tak (- z 1) x y))))
"""
def call_tak(vm):
for case in [(7, (18, 12, 6)),
(15, (30, 15, 9)),
(10, (33, 15, 9)),
(15, (40, 15, 9))]:
scm = vm.apply(vm.get("tak"), [vm.toscheme(x) for x in case[1]])
assert vm.fromscheme(scm) == case[0]
bm = Benchmark(title="tak benchmark", repeat=1)
for backend in helper.BACKENDS:
vm = helper.VM(backend=backend)
vm.eval(vm.compile(code))
bm.measure(backend, call_tak, vm)
helper.report(bm.report())
示例5: conversion
# 需要导入模块: from benchmark import Benchmark [as 别名]
# 或者: from benchmark.Benchmark import measure [as 别名]
# we don't asser the euqality because sometimes the time to
# test the equality may be longer than the conversion (e.g.
# when testing two big chunk of string).
vm.fromscheme(scm)
class Foo(object):
pass
BIG_TEXT = open(__file__).read()
cases = [("integers", [1, 10, -5]),
("float numbers", [0.5, -3.2, 0.0]),
("big numbers", [2**33, -2**34, 10**10]),
("bool values", [True, False, False]),
("strings", ["foo", "", "baz"]),
("big string", [BIG_TEXT, BIG_TEXT, BIG_TEXT]),
("symbols", [helper.Symbol("foo"), helper.Symbol(""), helper.Symbol("bar")]),
("cons pairs", [helper.Cons(1, 2), helper.Cons([], []), helper.Cons(1, helper.Cons(2, []))]),
("lists", [[1, 2, 3], [1, 2, 3, 4], []]),
("dicts", [{1:1, 2:2}, {}, {1:10, 10:1}]),
("callables", [__import__, do_convert, list.sort]),
("objects", [Foo(), Foo(), object()])
]
for case in cases:
bm = Benchmark(title="performance of converting " + case[0], repeat=1000)
for backend in helper.BACKENDS:
vm = helper.VM(backend=backend)
bm.measure(backend, do_convert, vm, case[1])
helper.report(bm.report())
示例6: sorted
# 需要导入模块: from benchmark import Benchmark [as 别名]
# 或者: from benchmark.Benchmark import measure [as 别名]
(define lst '(5 9 2 4 7 6 3 1 8 10 -5 83))
(define sorted (insertion-sort lst))
(sorted? sorted))
"""
def call_sort(vm, compiled):
scm = vm.eval(compiled)
assert vm.type(scm) is bool, "Type should be bool"
assert vm.fromscheme(scm) == True, "The array should be sorted"
bm = Benchmark(title="performance improvements by compiling (sort)", repeat=100)
for backend in helper.BACKENDS:
vm = helper.VM(backend=backend)
compiled = vm.compile(code_sort)
bm.measure(backend, call_sort, vm, compiled)
helper.report(bm.report())
code_calc = """
(begin
(define a 5)
(define b 10)
(define c (- a b))
(+ a
(* b 10 11)
(apply + (list (* b c) 1 2 (- 3 a) b 5))
9
b))