Commits

David Schneider  committed 1e831be

some tweaks and making it translate

  • Participants
  • Parent commits 27ea547
  • Branches continuation-based

Comments (0)

Files changed (2)

File prolog/builtin/statistics.py

 
 wall_start = time.time()
 # TODO: make this continuation based and return all statistics
+# RPYTHON??
 @expose_builtin("statistics", unwrap_spec=["atom", "obj"])
 def impl_statistics(engine, heap, stat_name, value):
+    t = []
     if stat_name == 'runtime':        
         t = [clock_time(), clocktime_since_last_call()]
     if stat_name == 'walltime':
         t = [walltime(), walltime_since_last_call()]
-    l = map(term.Number, t)
+    l = [term.Number(x) for x in t]
     helper.wrap_list(l).unify(value, heap)
+    
+start = int(time.time())
+clocks = {'cpu_last': 0, 'cpu_now': 0, 'wall_now':0, 'wall_last':0}
 
-clock_now = None
 def clock_time():
-    prolog.builtin.statistics.clock_now = int(time.clock()*1000)
-    return prolog.builtin.statistics.clock_now
+    clocks['cpu_now'] = int(time.clock()*1000)
+    return clocks['cpu_now']
     
-clock_last = 0
 def clocktime_since_last_call():
-    prolog.builtin.statistics.clock_last = prolog.builtin.statistics.clock_now - prolog.builtin.statistics.clock_last
-    return prolog.builtin.statistics.clock_last
+    t = clocks['cpu_now'] - clocks['cpu_last']
+    clocks['cpu_last'] = clocks['cpu_now']
+    return t
     
-wall_now = 0
 def walltime():
-    prolog.builtin.statistics.wall_now = int(time.time()*1000)
-    return prolog.builtin.statistics.wall_now    
+    clocks['wall_now'] = int((time.time()-start)*1000)
+    return clocks['wall_now']
 
-wall_last = 0
 def walltime_since_last_call():
-    prolog.builtin.statistics.wall_last = prolog.builtin.statistics.wall_now - prolog.builtin.statistics.wall_last
-    return prolog.builtin.statistics.wall_last
+    t = clocks['wall_now'] - clocks['wall_last']
+    clocks['wall_last'] = clocks['wall_now']
+    return t
     
 def reset_clocks():
-    prolog.builtin.statistics.clock_last = prolog.builtin.statistics.clock_now = 0
-    prolog.builtin.statistics.wall_last = prolog.builtin.statistics.wall_now = 0
+    prolog.builtin.statistics.clocks = {'cpu_last': 0, 'cpu_now': 0, 'wall_now':0, 'wall_last':0}

File prolog/builtin/test/test_statistics.py

     clock = clock_time()
     vars = assert_true("statistics(runtime, [A,B]).")
     assert vars['A'].num == vars['B'].num
+    assert vars['A'] != 0
     assert clock <= vars['A'].num
     
 def test_statistics_runtime_since_last_call():
     clock = walltime()
     vars = assert_true("statistics(walltime, [A,B]).")
     assert vars['A'].num == vars['B'].num
+    assert vars['A'].num != 0
     assert clock <= vars['A'].num
 
 def test_statistics_walltime_since_last_call():