problem with "time.time()"

here is an example of what’s not working the way I expected it to:

import bge                              
import GameLogic
import pprint
import time


cont = bge.logic.getCurrentController() 
own = cont.owner                       

own["timer"] = time.time() + 2.0
print (own["timer"])
print (time.time())

the output always looks something like this:

Blender Game Engine Started
1381970048.0
1381970079.644531
Blender Game Engine Finished

the first number is always truncated. it always looks like “*******.0”. it aslo doesn’t seem to add the 2.

I’m trying to use time.time() as a sort of timer. I have an idea of a workaround, but this is driving me nuts. the almost OCD part of me is tingling hard.

That is really weird. It looks like Blender is not using enough bits to store that value in memory. In WinXP 32bit, I had better results with “time.clock()”, have you tried that?

From what I can tell, Blender is not storing the result of “time.time()” correctly for some reason.

It is working correctly.

time.time() returns the current Unix time according to your computer’s clock.
time.clock() returns the number of seconds since the first call to clock() was made in that process.

If you want to time something properly, you need to first save the start time and then subtract the start time from the current time. You can use either time() or clock() for this, but you should choose one or the other, not both.

import time

startTime = time.time()

# do stuff
...

# get elapsed time
elapsedTime = time.time() - startTime

EDIT: It should be noted that time.clock() only behaves this way on Windows. On Unix systems it returns the current “processor time”. You can read more in the documentation.

EDIT2: Apprently you are right about the number not being stored properly in the object’s dictionary when using time.time(). time.clock() works fine though.