1. Displaying Updates Over Time
- Posted by euphoric (admin) Oct 07, 2010
- 1060 views
I've got a Euphoria program that could potentially iterate over some code millions of times. At first I was running this in a console and using a position() and printf() to display updates, but I know that takes a little time and, over the course of millions of iterations, could have a drastic affect on the time it takes to run. Or maybe not. Maybe that's something I should test.
Anyway, so then I used a if integer(counter/10000) then... to display an update, but I'm wondering if the "if" statement and division over every iteration is just as slow as a position()+puts() combo. Probably not, but it still takes time.
Now I'm wondering if setting up a timer in a multitasking task that hits every second might work. I'll give that a try, but I'd like to get ideas from everybody else.
Oh, I've thought of maybe a
if get_key() = ' ' then -- display some info end if
which is still an "if" but might be faster than an integer type-check plus division.
So, what's the best way to keep up-to-date on a program's process over millions of iterations? :)
2. Re: Displaying Updates Over Time
- Posted by DerekParnell (admin) Oct 07, 2010
- 1028 views
So, what's the best way to keep up-to-date on a program's process over millions of iterations?
Go to bed and check in the morning
But seriously ... try this.
atom dtrig . dtrig = time() + 60 . while looping do -- display progress every 60 seconds. if dtrig <= time() then display( whatever ) dtrig = time() + 60 end if . . . end while
3. Re: Displaying Updates Over Time
- Posted by unkmar Oct 07, 2010
- 1017 views
- Last edited Oct 08, 2010
I had been known to use a second counter.
atom millions integer show_it -- Should I show it yet? millions = 12345678 show_it = 0 for a = 1 to millions do if (not show_it and get_key() != -1) then -- Resets the counter. show_it = 1000 if (get_key() != -1 ) then -- Display if keypress in buffer puts(1, "Show iteration data\n") end if end if show_it -= 1 -- Reduce the display counter by one. end for
PS: I'm an old style euphoria coder. My code is v2.4 to v3.1 based. (Sorry)
4. Re: Displaying Updates Over Time
- Posted by unkmar Oct 08, 2010
- 1013 views
I had to fix a bug in my code. I had used:
if (not counter and get_key() = -1) then -- Reset counter if a key is pressed and counter is 0. counter = 1000 end if
The problem is that the counter will only be reset IF a key has been pressed during that iteration. If you miss it. then the counter continued to decrease into the negatives and never reach zero again.