Exemple #1
0
def do_basic_benchmarks():
    runtime = Runtime()
    module, _ = runtime.instantiate_module(runtime.load_module(BASIC_WASM))
    runtime.register_module('bench', module)

    thunk_delta = _run_basic_bench(runtime, module, 'thunk', (), 10000)
    add_delta = _run_basic_bench(runtime, module, 'add',
                                 (numpy.uint32(1), numpy.uint32(2)), 10000)
    call_thunk_delta = _run_basic_bench(runtime, module, 'call_thunk',
                                        (numpy.uint32(10000), ), 1)
    call_add_delta = _run_basic_bench(
        runtime,
        module,
        'call_add',
        (numpy.uint32(10000), numpy.uint32(1), numpy.uint32(2)),
        1,
    )

    logging.info(f"wrapped thunk: {call_thunk_delta / 10000:.8f} per call")
    logging.info(f"wrapped add  : {call_add_delta / 10000:.8f} per call")

    thunk_overhead = (call_thunk_delta - thunk_delta)
    add_overhead = call_add_delta - add_delta
    logging.info(
        f"call overhead for thunk: {thunk_overhead:.4f} ({100 * thunk_overhead / thunk_delta:.2f}%)  |   {thunk_overhead / 10000:.8f} per call"
    )  # noqa: E501
    logging.info(
        f"call overhead for add  : {add_overhead:.4f} ({100 * add_overhead / add_delta:.2f}%)  |   {add_overhead / 10000:.8f} per call"
    )  # noqa: E501
Exemple #2
0
def do_recursive_keccak(depth):
    runtime = Runtime()

    keccak_file = BASE_DIR / f"recursive_keccak_{depth}_wasm.wasm"
    if not keccak_file.exists():
        raise Exception(
            f"recursive keccak {depth} is not supported: {keccak_file} not found"
        )
    module, _ = runtime.instantiate_module(runtime.load_module(keccak_file))

    logging.info(f"BENCHMARKING: {depth} recursive keccak hashes")
    delta = time_fn(runtime, module, 'main', (), 1)
    logging.info(f"took: {delta:.4f}")
Exemple #3
0
def do_factorization_benchmarks(prime):
    runtime = Runtime()

    factorization_file = BASE_DIR / f"factorization_{prime}_reikna_wasm.wasm"
    if not factorization_file.exists():
        raise Exception(
            f"factorization {prime} is not supported: {factorization_file} not found"
        )
    module, _ = runtime.instantiate_module(
        runtime.load_module(factorization_file))

    logging.info(f"BENCHMARKING: factorization of {prime}")
    delta = time_fn(runtime, module, 'main', (), 1)
    logging.info(f"took: {delta:.4f}")
Exemple #4
0
def do_fibonacci_bigint_benchmarks(order):
    runtime = Runtime()

    fib_file = BASE_DIR / f"fibonacci_{order}_bigint_wasm.wasm"
    if not fib_file.exists():
        raise Exception(
            f"fibonacci {order} is not supported: {fib_file} not found")
    module, _ = runtime.instantiate_module(runtime.load_module(fib_file))

    logging.info(
        f"BENCHMARKING: recursive computation of fibonacci number {order} (wasm)"
    )
    delta = time_fn(runtime, module, 'main', (), 1)
    logging.info(f"took: {delta:.4f}")
Exemple #5
0
def instantiate_module_from_wasm_file(file_path: Path,
                                      runtime: Runtime) -> ModuleInstance:
    module = runtime.load_module(file_path)
    module_instance, _ = runtime.instantiate_module(module)

    return module_instance