OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace / examples / python / scheme_timer.py

34 lines · python ref:
#! /usr/bin/env python3

"""
Checks the execution time of repeated calls to the Scheme API from Python

Runs an empty Scheme command NUMBER_OF_ITERATIONS times and displays the
total execution time
"""

__author__ = 'Cosmo Harrigan'

from opencog.atomspace import AtomSpace
from opencog.scheme import *
atomspace = AtomSpace()

NUMBER_OF_ITERATIONS = 50000

def test_operation():
    for _ in range(NUMBER_OF_ITERATIONS):
        # scheme_eval(atomspace, '(+ 2 2)')
        scheme_eval_v(atomspace, '(Concept "foo")')
        # scheme_eval_v(atomspace, '(Number ' + str(i) + ')')

import timeit
elapsed = timeit.timeit("test_operation()",
                        setup="from __main__ import test_operation",
                        number=1)

def report():
    print ("{0} seconds elapsed performing {1} repeated calls = {2} calls / sec".\
        format(elapsed, NUMBER_OF_ITERATIONS, NUMBER_OF_ITERATIONS / elapsed))

report()