You are here: Home > Fastcode project > Ansi StringReplace Challenge

The Fastcode Project

Ansi StringReplace Challenge

The objective is to build the fastest partiel replacement for RTL StringReplace.

AnsiStringReplace is a replacement for the RTL StringReplace function, but valid for AnsiStrings only.

function StringReplace(const S, OldPattern, NewPattern: AnsiString; Flags: TReplaceFlags): AnsiString;

StringReplace replaces occurrences of the substring specified by OldPattern with the substring specified by NewPattern.  S is the source string, whose substrings are changed. OldPattern is the substring to locate and replace with NewPattern. NewPattern is the substring to substitute for occurrences of OldPattern. Flags is a set of flags that govern how StringReplace locates and replaces occurrences of OldPattern. If Flags does not include rfReplaceAll, StringReplace only replaces the first occurrence of OldPattern in S. Otherwise, StringReplace replaces all instances of OldPattern with NewPattern. If the Flags parameter includes rfIgnoreCase, The comparison operation is case insensitive.


It is not allowed to call any Fastcode functions not created by the function owner.

Validation and Benchmark Tool:

Tables of results

Tables of results - blind challenge

Target Function Author Speed up over RTL
P4 Prescott StringReplaceJOH_IA32_3 John O'Harrow 16,2
P4 Northwood StringReplaceJOH_IA32_3 John O'Harrow 16,7
Pentium M Dothan StringReplaceJOH_IA32_4 John O'Harrow 14,5

Pentium M Banias

StringReplaceJOH_IA32_3 John O'Harrow 14,7
AMD 64 StringReplaceJOH_IA32_3 John O'Harrow 11,1
Athlon XPOpteron StringReplaceJOH_IA32_3 John O'Harrow 12,3
Blended StringReplaceJOH_IA32_3 John O'Harrow 14,1
RTL Suggestion StringReplaceJOH_IA32_4 John O'Harrow 13,8
Pascal StringReplaceJOH_PAS_4 John O'Harrow 13,8