Python Interpreters Benchmarks
x64 ArchLinux : AMD® Ryzen 7 4700U®

 performance measurements

Each table row shows performance measurements for this program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
141.060.222,304741  70% 62% 59% 59% 59% 82% 59% 55%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read  benchmark to see what this program should do.


  source code

# The Computer Language Benchmarks Game
# contributed by Antoine Pitrou
# modified by Dominique Wahli and Daniel Nanz
# modified by Joerg Baumann

import sys
import multiprocessing as mp
import gc

def make_tree(i, d):
    if d > 0:
        d -= 1
        return (i, make_tree(i, d), make_tree(i + 1, d))
    return (i, None, None)

def check_tree(node):
    (i, l, r) = node
    if l is None:
        return i
        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
    if mp.cpu_count() > 1:
        pool = mp.Pool()
        chunkmap =
        chunkmap = map

    print('stretch tree of depth {0}\t check: {1}'.format(
          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(chunkmap(make_check, argchunk))
        print('{0}\t trees of depth {1}\t check: {2}'.format(i * 2, d, cs))

    print('long lived tree of depth {0}\t check: {1}'.format(
          max_depth, check_tree(long_lived_tree)))

if __name__ == '__main__':

 make, command-line, and program output logs

 Sun, 23 Apr 2023 08:41:51 GMT

make[1]: Vstupuje se do adresáře „/home/dundee/work/pybenchmarks/bencher/tmp/binarytrees/tmp“
nuitka3 --remove-output binarytrees.nuitka-7.nuitka
Nuitka-Options:INFO: Used command line options: --remove-output binarytrees.nuitka-7.nuitka
Nuitka-Options:WARNING: You did not specify to follow or include anything but main program. Check options and make sure that is intended.
Nuitka:INFO: Starting Python compilation with Nuitka '1.5' on Python '3.10' commercial grade 'not installed'.
Nuitka-Plugins:INFO: multiprocessing: Injecting pre-module load code for module 'multiprocessing':
Nuitka-Plugins:INFO: multiprocessing:     Monkey patching "multiprocessing" load environment.
Nuitka-Plugins:INFO: multiprocessing: Injecting post-module load code for module 'multiprocessing':
Nuitka-Plugins:INFO: multiprocessing:     Monkey patching "multiprocessing" for compiled methods.
Nuitka:INFO: Completed Python level compilation and optimization.
Nuitka:INFO: Generating source code for C backend compiler.
Nuitka:INFO: Running data composer tool for optimal constant value handling.
Nuitka:INFO: Running C compilation via Scons.
Nuitka-Scons:INFO: Backend C compiler: gcc (gcc).
Nuitka-Scons:INFO: Backend linking program with 10 files (no progress information available).
Nuitka-Scons:WARNING: You are not using ccache.
Nuitka:INFO: Removing build directory ''.
Nuitka:INFO: Successfully created 'binarytrees.nuitka-7.nuitka.bin'.
cp binarytrees.nuitka-7.nuitka.bin binarytrees.nuitka-7.nuitka_run
make[1]: Opouští se adresář „/home/dundee/work/pybenchmarks/bencher/tmp/binarytrees/tmp“
19.02s to complete and log all make actions

 ./binarytrees.nuitka-7.nuitka_run 14

stretch tree of depth 15	 check: -1
32768	 trees of depth 4	 check: -32768
8192	 trees of depth 6	 check: -8192
2048	 trees of depth 8	 check: -2048
512	 trees of depth 10	 check: -512
128	 trees of depth 12	 check: -128
32	 trees of depth 14	 check: -32
long lived tree of depth 14	 check: -1

Revised BSD license

  Home   Conclusions   License   Play