[fpc-pascal] FPC now 3rd in shootout
Marc Weustink
marc at dommelstein.net
Tue Nov 6 00:36:09 CET 2007
S. Fisher wrote:
> --- Marco van de Voort <marcov at stack.nl> wrote:
>
>>> http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=all
>>>
>>> The reason is that D's mean degraded from 1.40 to 1.43. I wonder how
>>> that could happen.
>> They change often. Clean is also quite variable. I assume the differences
>> are simply in the magnitude of the uncertainty of the measuring.
>
> I submitted this regex-dna program on 2007-10-31. It's still in limbo:
> neither accepted nor rejected.
>
> { The Computer Language Benchmarks Game
> http://shootout.alioth.debian.org
>
> contributed by Steve Fisher
>
> compile with
> fpc -O3 regex-dna.pp
> }
>
> uses regexpr, strutils;
>
> function replace_matches( const target: pchar; const repl: pchar;
> const str: ansistring; var dest: ansistring ): longint;
> var
> engine : tRegexprEngine;
> substr : ansistring;
> count, index, size : longint;
> begin
> if not GenerateRegExprEngine( target, [], engine) then
> begin
> writeln( 'Failed to generate regex. engine for "',target,'".' );
> halt(1)
> end;
> count := 0;
> dest := '';
> substr := str;
> while length(substr) > 0 do
> begin
> if RegExprPos(engine, pchar(substr), index, size ) then
> begin
> count += 1;
> dest += ansiLeftStr( substr, index) + repl;
> substr := ansiRightStr(substr,length(substr)-index-size);
> end
> else
> break
> end;
> DestroyRegExprEngine( engine );
> dest += substr;
> exit(count)
> end;
>
> function count_matches( target: pchar; const str: ansistring ): longint;
> var
> engine : tRegexprEngine;
> substr : ansistring;
> count, index, size : longint;
> begin
> if not GenerateRegExprEngine( target, [ref_caseinsensitive], engine) then
> begin
> writeln( 'Failed to generate regex. engine for "',target,'".' );
> halt(1)
> end;
For this benchmark you don't need extra unneeded code for checking
conditions. If the test fails it fails, so don't worry on errors
Marc
More information about the fpc-pascal
mailing list