Pyglet.clock.schedule significant function calling speed limitation









up vote
0
down vote

favorite












I encountered a certain inconsistency in the speed the Pyglet's pyglet.clock.schedule and pyglet.clock.schedule_interval (with the interval argument below some value), call the functions.



Both commands seem to show some common treshold of the interval with what they can call the function. It could be associated with the hardware performance limits if the treshold speed wasn't THAT low - max. about 30 calls of a function per second.



The test code and results can be seen below:



import pyglet
from time import time

window = pyglet.window.Window()

last_update = time()

def update(dt):
global last_update
print("dt: ", dt)
print('Measured dt: ', time()-last_update)
last_update = time()

@window.event
def on_draw():
dt = pyglet.clock.tick()
print('Last clock tick: ', dt, "n")

pyglet.clock.schedule(update)
pyglet.app.run()


The sample result:



dt: 0.030516604423768356
Measured dt: 0.03125262260437012
dt: 0.0007512663764779326
Measured dt: 0.0
Last clock tick: 0.0007512663764779326


Despite the dt = pyglet.clock.tick() inducing to recall the update(dt) function whose dt value states to be consistent with the expectated clock.tick() returned value, the first call almost always returns the same, fixed dt's value, indicating the maximum frequency the Pyglet's interval functions call the callback function is about 30 - 32 times per second.



I'm not sure what may influence such a low frequency but I guess such performance may be an effect of some kind of a malfunction. The evidence seem to be at least the utilization of the higher framerates (e.g. 120 FPS) among the publishers' examplary programs.



What can be the reason for it working so slowly and could the pyglet's interval functions somehow be fixed to update the callback functions with the corresponding, given frequency, not limited to the modest ~30 per second? Thanks you for help in advance.



PS The clock.schedule_interval can only be manipulated, if its interval is about above 1/30.



PPS The occurance of print methods doesn't influence the interval functions' treshold speed.










share|improve this question



























    up vote
    0
    down vote

    favorite












    I encountered a certain inconsistency in the speed the Pyglet's pyglet.clock.schedule and pyglet.clock.schedule_interval (with the interval argument below some value), call the functions.



    Both commands seem to show some common treshold of the interval with what they can call the function. It could be associated with the hardware performance limits if the treshold speed wasn't THAT low - max. about 30 calls of a function per second.



    The test code and results can be seen below:



    import pyglet
    from time import time

    window = pyglet.window.Window()

    last_update = time()

    def update(dt):
    global last_update
    print("dt: ", dt)
    print('Measured dt: ', time()-last_update)
    last_update = time()

    @window.event
    def on_draw():
    dt = pyglet.clock.tick()
    print('Last clock tick: ', dt, "n")

    pyglet.clock.schedule(update)
    pyglet.app.run()


    The sample result:



    dt: 0.030516604423768356
    Measured dt: 0.03125262260437012
    dt: 0.0007512663764779326
    Measured dt: 0.0
    Last clock tick: 0.0007512663764779326


    Despite the dt = pyglet.clock.tick() inducing to recall the update(dt) function whose dt value states to be consistent with the expectated clock.tick() returned value, the first call almost always returns the same, fixed dt's value, indicating the maximum frequency the Pyglet's interval functions call the callback function is about 30 - 32 times per second.



    I'm not sure what may influence such a low frequency but I guess such performance may be an effect of some kind of a malfunction. The evidence seem to be at least the utilization of the higher framerates (e.g. 120 FPS) among the publishers' examplary programs.



    What can be the reason for it working so slowly and could the pyglet's interval functions somehow be fixed to update the callback functions with the corresponding, given frequency, not limited to the modest ~30 per second? Thanks you for help in advance.



    PS The clock.schedule_interval can only be manipulated, if its interval is about above 1/30.



    PPS The occurance of print methods doesn't influence the interval functions' treshold speed.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I encountered a certain inconsistency in the speed the Pyglet's pyglet.clock.schedule and pyglet.clock.schedule_interval (with the interval argument below some value), call the functions.



      Both commands seem to show some common treshold of the interval with what they can call the function. It could be associated with the hardware performance limits if the treshold speed wasn't THAT low - max. about 30 calls of a function per second.



      The test code and results can be seen below:



      import pyglet
      from time import time

      window = pyglet.window.Window()

      last_update = time()

      def update(dt):
      global last_update
      print("dt: ", dt)
      print('Measured dt: ', time()-last_update)
      last_update = time()

      @window.event
      def on_draw():
      dt = pyglet.clock.tick()
      print('Last clock tick: ', dt, "n")

      pyglet.clock.schedule(update)
      pyglet.app.run()


      The sample result:



      dt: 0.030516604423768356
      Measured dt: 0.03125262260437012
      dt: 0.0007512663764779326
      Measured dt: 0.0
      Last clock tick: 0.0007512663764779326


      Despite the dt = pyglet.clock.tick() inducing to recall the update(dt) function whose dt value states to be consistent with the expectated clock.tick() returned value, the first call almost always returns the same, fixed dt's value, indicating the maximum frequency the Pyglet's interval functions call the callback function is about 30 - 32 times per second.



      I'm not sure what may influence such a low frequency but I guess such performance may be an effect of some kind of a malfunction. The evidence seem to be at least the utilization of the higher framerates (e.g. 120 FPS) among the publishers' examplary programs.



      What can be the reason for it working so slowly and could the pyglet's interval functions somehow be fixed to update the callback functions with the corresponding, given frequency, not limited to the modest ~30 per second? Thanks you for help in advance.



      PS The clock.schedule_interval can only be manipulated, if its interval is about above 1/30.



      PPS The occurance of print methods doesn't influence the interval functions' treshold speed.










      share|improve this question















      I encountered a certain inconsistency in the speed the Pyglet's pyglet.clock.schedule and pyglet.clock.schedule_interval (with the interval argument below some value), call the functions.



      Both commands seem to show some common treshold of the interval with what they can call the function. It could be associated with the hardware performance limits if the treshold speed wasn't THAT low - max. about 30 calls of a function per second.



      The test code and results can be seen below:



      import pyglet
      from time import time

      window = pyglet.window.Window()

      last_update = time()

      def update(dt):
      global last_update
      print("dt: ", dt)
      print('Measured dt: ', time()-last_update)
      last_update = time()

      @window.event
      def on_draw():
      dt = pyglet.clock.tick()
      print('Last clock tick: ', dt, "n")

      pyglet.clock.schedule(update)
      pyglet.app.run()


      The sample result:



      dt: 0.030516604423768356
      Measured dt: 0.03125262260437012
      dt: 0.0007512663764779326
      Measured dt: 0.0
      Last clock tick: 0.0007512663764779326


      Despite the dt = pyglet.clock.tick() inducing to recall the update(dt) function whose dt value states to be consistent with the expectated clock.tick() returned value, the first call almost always returns the same, fixed dt's value, indicating the maximum frequency the Pyglet's interval functions call the callback function is about 30 - 32 times per second.



      I'm not sure what may influence such a low frequency but I guess such performance may be an effect of some kind of a malfunction. The evidence seem to be at least the utilization of the higher framerates (e.g. 120 FPS) among the publishers' examplary programs.



      What can be the reason for it working so slowly and could the pyglet's interval functions somehow be fixed to update the callback functions with the corresponding, given frequency, not limited to the modest ~30 per second? Thanks you for help in advance.



      PS The clock.schedule_interval can only be manipulated, if its interval is about above 1/30.



      PPS The occurance of print methods doesn't influence the interval functions' treshold speed.







      python pyglet






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 5:49

























      asked Nov 12 at 2:51









      Pear Bloom

      11




      11






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Try to set the FPS limit to a higher value:



          pyglet.clock.set_fps_limit(60)


          Looks like pyglet sets this limit to a quite low value by default is some cases: FPS with Pyglet half of monitor refresh rate



          It may also help the set vsync to false:



          class Window(pyglet.window.Window):
          def __init__(self, refreshrate):
          super(Window, self).__init__(vsync = False)


          Edit: As pointed out in the comments, set_fps_limit is deprecated. A solution with schedule_interval would look somehow like:



          pyglet.clock.schedule_interval(self.on_draw, 1.0/60.0)





          share|improve this answer


















          • 1




            pyglet.readthedocs.io/en/pyglet-1.3-maintenance/modules/… set_fps_limit is deprecated
            – Yuriy Leonov
            Nov 12 at 13:38











          • You are right, I didn't know that. Btw: The linked SO question also contains an answer which uses schedule_interval which seems to be the preferred way now.
            – Sebastian
            Nov 12 at 14:11










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255392%2fpyglet-clock-schedule-significant-function-calling-speed-limitation%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          Try to set the FPS limit to a higher value:



          pyglet.clock.set_fps_limit(60)


          Looks like pyglet sets this limit to a quite low value by default is some cases: FPS with Pyglet half of monitor refresh rate



          It may also help the set vsync to false:



          class Window(pyglet.window.Window):
          def __init__(self, refreshrate):
          super(Window, self).__init__(vsync = False)


          Edit: As pointed out in the comments, set_fps_limit is deprecated. A solution with schedule_interval would look somehow like:



          pyglet.clock.schedule_interval(self.on_draw, 1.0/60.0)





          share|improve this answer


















          • 1




            pyglet.readthedocs.io/en/pyglet-1.3-maintenance/modules/… set_fps_limit is deprecated
            – Yuriy Leonov
            Nov 12 at 13:38











          • You are right, I didn't know that. Btw: The linked SO question also contains an answer which uses schedule_interval which seems to be the preferred way now.
            – Sebastian
            Nov 12 at 14:11














          up vote
          0
          down vote













          Try to set the FPS limit to a higher value:



          pyglet.clock.set_fps_limit(60)


          Looks like pyglet sets this limit to a quite low value by default is some cases: FPS with Pyglet half of monitor refresh rate



          It may also help the set vsync to false:



          class Window(pyglet.window.Window):
          def __init__(self, refreshrate):
          super(Window, self).__init__(vsync = False)


          Edit: As pointed out in the comments, set_fps_limit is deprecated. A solution with schedule_interval would look somehow like:



          pyglet.clock.schedule_interval(self.on_draw, 1.0/60.0)





          share|improve this answer


















          • 1




            pyglet.readthedocs.io/en/pyglet-1.3-maintenance/modules/… set_fps_limit is deprecated
            – Yuriy Leonov
            Nov 12 at 13:38











          • You are right, I didn't know that. Btw: The linked SO question also contains an answer which uses schedule_interval which seems to be the preferred way now.
            – Sebastian
            Nov 12 at 14:11












          up vote
          0
          down vote










          up vote
          0
          down vote









          Try to set the FPS limit to a higher value:



          pyglet.clock.set_fps_limit(60)


          Looks like pyglet sets this limit to a quite low value by default is some cases: FPS with Pyglet half of monitor refresh rate



          It may also help the set vsync to false:



          class Window(pyglet.window.Window):
          def __init__(self, refreshrate):
          super(Window, self).__init__(vsync = False)


          Edit: As pointed out in the comments, set_fps_limit is deprecated. A solution with schedule_interval would look somehow like:



          pyglet.clock.schedule_interval(self.on_draw, 1.0/60.0)





          share|improve this answer














          Try to set the FPS limit to a higher value:



          pyglet.clock.set_fps_limit(60)


          Looks like pyglet sets this limit to a quite low value by default is some cases: FPS with Pyglet half of monitor refresh rate



          It may also help the set vsync to false:



          class Window(pyglet.window.Window):
          def __init__(self, refreshrate):
          super(Window, self).__init__(vsync = False)


          Edit: As pointed out in the comments, set_fps_limit is deprecated. A solution with schedule_interval would look somehow like:



          pyglet.clock.schedule_interval(self.on_draw, 1.0/60.0)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 14:12

























          answered Nov 12 at 7:43









          Sebastian

          3,01932344




          3,01932344







          • 1




            pyglet.readthedocs.io/en/pyglet-1.3-maintenance/modules/… set_fps_limit is deprecated
            – Yuriy Leonov
            Nov 12 at 13:38











          • You are right, I didn't know that. Btw: The linked SO question also contains an answer which uses schedule_interval which seems to be the preferred way now.
            – Sebastian
            Nov 12 at 14:11












          • 1




            pyglet.readthedocs.io/en/pyglet-1.3-maintenance/modules/… set_fps_limit is deprecated
            – Yuriy Leonov
            Nov 12 at 13:38











          • You are right, I didn't know that. Btw: The linked SO question also contains an answer which uses schedule_interval which seems to be the preferred way now.
            – Sebastian
            Nov 12 at 14:11







          1




          1




          pyglet.readthedocs.io/en/pyglet-1.3-maintenance/modules/… set_fps_limit is deprecated
          – Yuriy Leonov
          Nov 12 at 13:38





          pyglet.readthedocs.io/en/pyglet-1.3-maintenance/modules/… set_fps_limit is deprecated
          – Yuriy Leonov
          Nov 12 at 13:38













          You are right, I didn't know that. Btw: The linked SO question also contains an answer which uses schedule_interval which seems to be the preferred way now.
          – Sebastian
          Nov 12 at 14:11




          You are right, I didn't know that. Btw: The linked SO question also contains an answer which uses schedule_interval which seems to be the preferred way now.
          – Sebastian
          Nov 12 at 14:11

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255392%2fpyglet-clock-schedule-significant-function-calling-speed-limitation%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3