Hi everyone! I recently bought the Casio Graph Math+. I've been testing out Python programming and the new getkey() function. I've run into a peculiar behavior and thought I'd ask for your opinion:

While non-blocking, it seems a call getkey() will still take a significant amount of time if no key is being pressed. However, if a key is being pressed, getkey() returns the key code in a negligible amount of time. For a loop that calls getkey(), this can result in a very noticeable difference in performance depending on key up or key down state.

At the end of this post is a simple example script. It loops indefinitely and prints the loop count and currently pressed key code. Try running it with and without a key pressed. Also try without the getkey() call. In my tests, I measured the following performance for 2000 iterations:

No getkey() call: 33 seconds
getkey(), no button pressed: 49 seconds
getkey(), button pressed: 33 seconds

Maybe this is expected behavior, maybe not. I was at least a bit surprised. Would appreciate any input on this.


Code:
from casioplot import *

i = 0
while 1:
  clear_screen()
  i = i + 1
  key = getkey()
  draw_string(100,100,str(i))
  draw_string(200,100,str(key))
  show_screen()
I've felt that getkey() was a bit slow sometimes, alhough... that's quite something. 16 extra seconds over 2000 iterations means a whole 8 ms when a key is not pressed! I'll have to check on mine. There is an experimental port of PythonExtra for the Math+ currently, which hopefully should not have that problem.
Yeah, I did another test with a simpler loop (not involving any screen updates) and 10 000 iterations. The result was basically the same in terms of time spent per getkey() call: ~8.2 ms. Again, if a key was kept pressed down, no performance decrease was seen even over 10 000 iterations.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement