Skip to content

cache attributes that never change - #564

Merged
dwalton76 merged 2 commits into
ev3dev:ev3dev-stretchfrom
dwalton76:cache_constant_properties
Nov 13, 2018
Merged

dwalton76 merged 2 commits into
ev3dev:ev3dev-stretchfrom
dwalton76:cache_constant_properties

Conversation

@dwalton76

Copy link
Copy Markdown
Collaborator

For issue #365

@dwalton76

Copy link
Copy Markdown
Collaborator Author

Tested with

#!/usr/bin/env python3

from time import perf_counter
from ev3dev2.motor import OUTPUT_A, OUTPUT_B, LargeMotor

lMotor = LargeMotor(OUTPUT_A)
rMotor = LargeMotor(OUTPUT_B)

LOOPS = 10000
lMotor.run_forever()
rMotor.run_forever()

# without caching this takes 7290ms
# with caching it takes 1325ms
startTime = perf_counter()
for a in range(0,LOOPS):
    lMotor.commands
    rMotor.commands
    lMotor.driver_name
    rMotor.driver_name
    lMotor.count_per_rot
    rMotor.count_per_rot
    lMotor.count_per_m
    rMotor.count_per_m
    lMotor.max_speed
    rMotor.max_speed
    lMotor.full_travel_count
    rMotor.full_travel_count

endTime = perf_counter()
lMotor.stop()
rMotor.stop()

print("{}s".format(endTime - startTime))
  • without caching this takes 7290ms
  • with caching it takes 1325ms

Comment thread ev3dev2/__init__.py Resolved
Comment thread ev3dev2/motor.py Resolved
Comment thread ev3dev2/port.py Resolved
Comment thread ev3dev2/port.py Resolved
@dwalton76
dwalton76 merged commit 0d60fca into ev3dev:ev3dev-stretch Nov 13, 2018
@dwalton76
dwalton76 deleted the cache_constant_properties branch November 13, 2018 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants