* harbour/include/hbexprb.c
+ enabled o:var += <cString> optimization when -ko switch is used
I added this optimization few years ago but I haven't enabled it
so far.
+ harbour/tests/speedstr.prg
+ added test code for <exp> += <cString> optimization
Try this code compiled with -kc switch (disabled += optimization)
without any -k? switches (default, += optimized for all expressions
except <obj>:<msg>) and finally with -ko switch (+= optimized for
all expressions)
(Warning for larger string non optimized code begins to be _very_
slow, i.e. for '#define N_LOOP 1000000' it needs fee minutes to
pass single test)
78 lines
1.4 KiB
Plaintext
78 lines
1.4 KiB
Plaintext
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
* Harbour Project source code:
|
|
* speed test program for string concatenation by += operator
|
|
*
|
|
* Copyright 2011 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
|
|
* www - http://harbour-project.org
|
|
*
|
|
*/
|
|
|
|
#define N_LOOP 200000
|
|
|
|
#ifndef __XHARBOUR__
|
|
#translate secondsCPU( => hb_secondsCPU(
|
|
#endif
|
|
#ifdef __XPP__
|
|
#translate secondsCPU( => seconds(
|
|
#endif
|
|
#ifdef __HARBOUR__
|
|
#include "hbclass.ch"
|
|
#endif
|
|
|
|
proc main()
|
|
memvar p
|
|
local i, t
|
|
local l, o
|
|
static s, s2[1]
|
|
private p
|
|
p := s2[1] := s := l := ""
|
|
t := secondsCPU()
|
|
for i := 1 to N_LOOP
|
|
l += chr( i )
|
|
next
|
|
t := secondsCPU() - t
|
|
? "LOCAL +=", t, "sec."
|
|
t := secondsCPU()
|
|
for i := 1 to N_LOOP
|
|
s += chr( i )
|
|
next
|
|
t := secondsCPU() - t
|
|
? "STATIC +=", t, "sec."
|
|
t := secondsCPU()
|
|
for i := 1 to N_LOOP
|
|
s2[1] += chr( i )
|
|
next
|
|
t := secondsCPU() - t
|
|
? "ARRAY[] +=", t, "sec."
|
|
t := secondsCPU()
|
|
for i := 1 to N_LOOP
|
|
p += chr( i )
|
|
next
|
|
t := secondsCPU() - t
|
|
? "PRIVATE +=", t, "sec."
|
|
p := ""; s := "p"
|
|
t := secondsCPU()
|
|
for i := 1 to N_LOOP
|
|
&s += chr( i )
|
|
next
|
|
t := secondsCPU() - t
|
|
? "MACRO +=", t, "sec."
|
|
o := mycls():new(); o:v := ""
|
|
t := secondsCPU()
|
|
for i := 1 to N_LOOP
|
|
o:v += chr( i )
|
|
next
|
|
t := secondsCPU() - t
|
|
? "OBJECT:VAR +=", t, "sec."
|
|
wait
|
|
return
|
|
|
|
class mycls
|
|
exported:
|
|
var v
|
|
endclass
|