What am I missing here? [FastImage question]

Blitz3D Forums/Blitz3D Userlibs/What am I missing here? [FastImage question]

Yasha(Posted 2011) [#1]
Hi all. Some strangeness when trying to use a benchmark with FastImage...

My program makes heavy use of rounded rectangles. So I took a look at the supplied DrawRoundedRect function and *gasp* it creates, fills, and then frees a new bank each time the rect is drawn! Bank operations (create/poke/free - all of them) are slow, especially when they're not necessary, so I thought I could speed things up by creating my rounded rect banks in advance and storing them in the GUI object to draw.

Here's a speed test:


...using this very slightly modified RoundedRect include:


Three tests. First, create the bank in advance and try to draw using the same one each time, just passing it to DrawPoly. Second, use the supplied function. Third, use another modified version of the supplied function that doesn't draw, just so we can see how much time the bank operations cost.

My results (fairly consistent across several runs):
Cached time: 2119
Default time: 2155
Bank operations time: 801

...hang on, what? Those figures don't add up!

In terms of operations, the cached function is the default function minus the bank operations (i.e. it only calls DrawPoly instead of all of the bank stuff). Yet even though the bank functions appear to take up around 38% of the entire time of DrawRoundedRect, removing them only gives a 1% difference in speed. How does that make sense?

Does DrawPoly have to wait on some kind of internal graphics card timer? (That's literally the only thing I can think of.) Or have I looked at this too hard and for too long and am ignoring the giant red call to TIME_WASTING_FUNCTION() I inadvertently slipped into the benchmark?

(And no, it's not the For loop. 100K iterations of a loop doesn't use a measurable amount of time on my machine.)


For the record, I care less about the "optimisation" (which I probably won't use, it complicates the drawing logic) than I do about why doesn't my maths add up?

Last edited 2011


Rob the Great(Posted 2011) [#2]
I'm not getting similar results as what you're showing. Keep in mind that I'm using a wimpy laptop right now.

Cached: 13384
Default: 31853
Banks: 1136

This is consistant from five tests, always within 1 second. I'm trying to puzzle out what could cause this, but I'm drawing a bank (Misspelling intended).

Specs:
Blitz3D Version 1.100
Window Vista Home Premium
32 Bit OS, AMD Turion 64 X2 TL-50, 1.60Ghz
894 MB Ram (Nothing special about the specs on this laptop)


Floyd(Posted 2011) [#3]
I'll take a guess, without trying to understand the details of your program.

This sort of thing usually happens because the computer ( CPU ) and graphics card ( GPU ) run simultaneously. The programs does something like:

Repeat
   Calculate
   Draw
Until done

The CPU issues drawing commands to the GPU and then continues with its own work without waiting for the drawing operations to finish. The total time used might be little more that the larger of the times used by CPU and GPU, assuming a great deal of overlap.


Yasha(Posted 2011) [#4]
Thanks for those suggestions. I think I see why that would cause the apparently odd results - The different but still odd results from Rob probably mean that that machine is syncing at a slightly different rate or something.

Based on this, I decided the idea is still useful, since even if it doesn't manifest as a speed up, making the CPU work less is always good. And then found a much, much simpler way to do what I want... yay.