Skip to content

Commit

Permalink
Switched to 'time' from 'datetime' library for time utility functions
Browse files Browse the repository at this point in the history
based on the advices of @jeremydouglass and @gvrancken. I have switched from 'datetime' to 'time' to improve performance.

Related to #129
  • Loading branch information
arihantparsoya committed Nov 24, 2019
1 parent 2e8de54 commit 531fa35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions p5/pmath/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

import datetime
import time
import builtins


def millis():
return int((time.perf_counter() - builtins.start_time)*1000)

def day():
return datetime.datetime.now().day
return int(time.strftime("%d"))

def hour():
return datetime.datetime.now().hour

def millis():
return (datetime.datetime.now() - builtins.start_time).total_seconds()*1000
return int(time.strftime("%H"))

def minute():
return datetime.datetime.now().minute
return int(time.strftime("%M"))

def second():
return datetime.datetime.now().second
return int(time.strftime("%S"))

def year():
return datetime.datetime.now().year

return int(time.strftime("%Y"))
4 changes: 2 additions & 2 deletions p5/sketch/userspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import math
import numpy as np
import builtins
import datetime
import time
from functools import wraps

from vispy import app
Expand Down Expand Up @@ -154,7 +154,7 @@ def run(sketch_setup=None, sketch_draw=None, frame_rate=60, mode="P2D"):

builtins.pixel_x_density = physical_width // width
builtins.pixel_y_density = physical_height // height
builtins.start_time = datetime.datetime.now()
builtins.start_time = time.perf_counter()

p5.sketch.timer.start()

Expand Down

0 comments on commit 531fa35

Please sign in to comment.