Skip to content

Instantly share code, notes, and snippets.

@wjwwood
Created July 28, 2011 04:18
Show Gist options
  • Save wjwwood/1110955 to your computer and use it in GitHub Desktop.
Save wjwwood/1110955 to your computer and use it in GitHub Desktop.
Blender time example
Blender Game Engine Started
1th iteration with time period 0.03333333333333333
2th iteration with time period 0.06666666666666667
3th iteration with time period 0.1
4th iteration with time period 0.13333333333333333
5th iteration with time period 0.16666666666666666
6th iteration with time period 0.2
7th iteration with time period 0.23333333333333334
8th iteration with time period 0.26666666666666666
9th iteration with time period 0.3
10th iteration with time period 0.3333333333333333
Run time: 0.9037580490112305
11th iteration with time period 0.36666666666666664
12th iteration with time period 0.4
13th iteration with time period 0.43333333333333335
14th iteration with time period 0.4666666666666667
15th iteration with time period 0.5
16th iteration with time period 0.5333333333333333
17th iteration with time period 0.5666666666666667
18th iteration with time period 0.6
19th iteration with time period 0.6333333333333333
Blender Game Engine Finished
# Python System (wall) Time
import time
# Blender Game Engine
import bge
logic_rate = 30.0
# Set the blender logic tic rate in Hz
# This drives the frame rate and is different
# from the physics tic rate.
bge.logic.setLogicTicRate(logic_rate)
physics_rate = 60.0
# Set the blender physics tic rate in Hz
bge.logic.setPhysicsTicRate(physics_rate)
count = 0
target_count = 10
work_period = 1.0/10.0
start_time = time.time()
def do_work():
global count, target_count, work_period, start_time
count += 1
print(str(count)+'th iteration with time period', count*(1.0/logic_rate))
# Check if we have iterated 100 times
if count == target_count:
print('Run time:',time.time()-start_time)
bge.logic.endGame()
# Get the time
then = time.time()
# Do work
while time.time() - then < work_period:
a = 1 # Hard work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment