Liste des Groupes | Revenir à cl c |
On Tue, 19 Mar 2024 21:40:22 -0700
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>Michael S <already5chosen@yahoo.com> writes:>
>On Mon, 18 Mar 2024 22:42:14 -0700>
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>Tim Rentsch <tr.17687@z991.linuxsc.com> writes:>
>
[...]
>
Here is the refinement that uses a resizing rather than
fixed-size buffer.
[code]
This variant is significantly slower than Malcolm's.
2x slower for solid rectangle, 6x slower for snake shape.
Slower with some shapes, faster in others.
In my small test suit I found no cases where this specific code is
measurably faster than code of Malcolm.
I did find one case in which they are approximately equal. I call
it "slalom shape" and it's more or less designed to be the worst
case for algorithms that are trying to speed themselves by take
advantage of straight lines.
The slalom shape is generated by following code:
[code]
In any case>
the code was written for clarity of presentation, with
no attention paid to low-level performance.
Yes, your code is easy to understand. Could have been easier
still if persistent indices had more meaningful names.
In other post I showed optimized variant of your algorithm: -
4-neighbors loop unrolled. Majority of the speed up come not from
unrolling itself, but from specialization of in-rectangle check
enabled by unroll.
- Todo queue implemented as circular buffer.
- Initial size of queue increased.
This optimized variant is more competitive with 'line-grabby'
algorithms in filling solid shapes and faster than them in
'slalom' case.
Generally, I like your algorithm.
It was surprising for me that queue can work better than stack, my
intuition suggested otherwise, but facts are facts.
>Besides, I don't think that use of VLA in library code is a good>
idea. VLA is optional in latest C standards. And incompatible
with C++.
The code uses a variably modified type, not a variable length
array.
I am not sufficiently versed in C Standard terminology to see a
difference.
Aren't they both introduced in C99 and made optional in later
standards?
Again, the choice is for clarity of presentation. If>
someone wants to get rid of the variably modified types, it's
very easy to do, literally a five minute task.
Yes, that's what it took for me.
But I knew that variably modified types exist, even if I didn't know
that they are called such.
OTOH, many (majority?) of C programmers never heard about them.
Anyway the interface is poorly designed to start with, [...]>
That's true. [...]
If someone wants to use the functionality from C++, it's>
easy enough to write a C wrapper function to do that.
IMO C++ has diverged sufficiently from C so that there
is little to be gained by trying to make code interoperable
between the two languages.
From the practical perspective, the biggest obstacle is that your
code can't be compiled with popular Microsoft compilers.
Les messages affichés proviennent d'usenet.