OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
scheme_timer.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 """
4 Checks the execution time of repeated calls to the Scheme API from Python
5 
6 Runs an empty Scheme command NUMBER_OF_ITERATIONS times and displays the
7 total execution time
8 """
9 
10 __author__ = 'Cosmo Harrigan'
11 
12 NUMBER_OF_ITERATIONS = 50000
13 
14 from opencog.atomspace import AtomSpace, TruthValue, types, get_type_name
15 from opencog.scheme_wrapper import load_scm, scheme_eval, scheme_eval_h, __init__
16 
17 atomspace = AtomSpace()
18 __init__(atomspace)
19 
20 data = ["opencog/atomspace/core_types.scm",
21  "opencog/scm/utilities.scm"]
22 
23 for item in data:
24  load_scm(atomspace, item)
25 
26 
28  for i in range(NUMBER_OF_ITERATIONS):
29  scheme_eval(atomspace, '(+ 2 2)')
30 
31 import timeit
32 elapsed = timeit.timeit("test_operation()",
33  setup="from __main__ import test_operation",
34  number=1)
35 
36 print "{0} seconds elapsed performing {1} repeated calls = {2} calls / sec".\
37  format(elapsed, NUMBER_OF_ITERATIONS, NUMBER_OF_ITERATIONS / elapsed)