Steve Loft wrote:
On Sunday 28 January 2001 10:09 pm, Frank Heckenbach wrote:
procedure FillChar (var Dest; Count: SizeType; Val: Char); or procedure FillChar (var Dest; Count: SizeType; Val: Byte);
Thanks (both of you). I tried that on an array[1..1000,1..1000] of integer, and the difference in time taken between
for i := 1 to 1000 do for j := 1 to 1000 do x[i,j] := 0;
and
fillchar(x, sizeof(x), 0)
was very small (the first took 18637 usec and the second took 17478 usec). But replacing sizeof(x) with 1000000 made it much faster (5348 usec).
Well, the size of an Integer is 4 bytes, so the size of the array is 4000000. If you fill 1000000 bytes, you only fill 1/4 of it which is clearly faster. :-)
If the size of the array is known at compile time (i.e., no schema and no dynamic array), SizeOf is evaluated at compile time. In fact, you'll find that the executables produced with SizeOf(x) vs. 4000000 will be identical.
Do you have any feeling for how efficient the code produced by gpc is? Is it something you're looking to improve, or are you happy with it? I find that code compiled with gpc runs at about 75% of the speed of equivalent code compiled with gcc (using -O3 -march=i686 in both cases). Is this just a fact of life of using Pascal?
In general, most of the code produced is a good as that of gcc since they share the code generator. But in some areas, there are noticeable differences, especially the handling of strings is not quite optimal currently. We're hoping to improve this when we get around to it, but most of the time, feature requests and bug fixed have higher precedence...
Frank