ScheduleTask in Mathematica, does it have any limit on time interval to use?
I am having a little bit of hard time understanding ScheduledTask[]. This was added in V 8.
On windows 7, 64 bit, using V 8.01, when I run the following code
dt = 0.01;
c = 0;
Dynamic[c]
task = CreateScheduledTask[c += 1, {dt, 100}];
StartScheduledTask[task];
I get 'c' ending with value 51, not 100 as ex开发者_StackOverflow中文版pected.
When I change 'dt' above to larger value, say 0.02, or any other larger value than 0.02 seconds, only then I get 100 each time.
If I make 'dt' 0.005, I end up with c=27. Make 'dt' 0.0025, c becomes 18, and so on.
So, the 'dt' limit (CPU time granularity) seems to be 0.02 to get what I want. This is 20 milliseconds.
But from other web sites, I see that windows 7 (depending on HW ofcourse) can provide cpu clock resolution much smaller than this. May be 1-10 milliseconds.
Am I missing something here, or did I misunderstand this function?
Help on this function says
creates a task that will try evaluating expr once every time seconds up to count times total
I could not find more information on this using Mathematica own documentation, but I could have overlooked it.
documentation for this function is http://reference.wolfram.com/mathematica/ref/CreateScheduledTask.html
Thanks ps. to remove task when done, the command is
RemoveScheduledTask[task]
or to clean everything:
RemoveScheduledTask[ScheduledTasks[]]
Hardware I have is: Intel i7 CPU 930, 2.8 Ghz 4 core
Although the windows timer reportedly can measure into the ns granularity the task scheduler has a much lower granularity. I found it reported (here and here) to be between 10-15ms and multiples of 20 ms, respectively. I think you should therefore use a minimum of 20 ms spacing to be sure and then you still aren't guaranteed to get a slot, so you should never depend on it.
精彩评论