From: William James Date: 2008-03-11T23:20:15+09:00 Subject: Re: duplicating characters in a string On Mar 7, 11:45 pm, Joel VanderWerf wrote: > Rehearsal --------------------------------------------------- > s.gsub(re){...} 6.220000 0.010000 6.230000 ( 6.325230) > s.gsub(re,...) 3.020000 0.060000 3.080000 ( 3.115286) > 7stud 4.110000 0.000000 4.110000 ( 4.142912) > 7stud 2.050000 0.000000 2.050000 ( 2.072398) > ----------------------------------------- total: 15.470000sec > > user system total real > s.gsub(re){...} 5.910000 0.020000 5.930000 ( 5.993456) > s.gsub(re,...) 3.000000 0.000000 3.000000 ( 3.017119) > 7stud 4.100000 0.020000 4.120000 ( 4.300772) > 7stud 2.030000 0.010000 2.040000 ( 2.068190) Pascal (FreePascal): uses sysutils; // for timing function dup_chars( s: ansistring ): ansistring; var out: ansistring; i,j: longint; c: char; begin setlength( out, length(s) * 2 ); for i := 1 to length(s) do begin c := s[i]; j := (i shl 1); out[j-1] := c; out[j] := c; end; exit( out ) end; var s : ansistring; i : longint; when : tDateTime; begin s := ''; for i:=1 to 1000000 do s += 'abc'; when := Time; dup_chars( s ); writeln( ((time - when) * secsPerDay):0:3, ' seconds' ) end. --->0.031 seconds