Author Topic: String Append  (Read 2380 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2685
    • ScriptBasic Open Source Project
String Append
« on: February 06, 2016, 11:07:00 PM »
Quote from: John Script BASIC
Code: Script BASIC
  1. BLA$ = ""
  2.  
  3. FOR i = 1 TO 50000
  4.     BLA$ &= "@"
  5. NEXT
  6. PRINT LEN(BLA$),"\n"
  7.  


jrs@laptop:~/sb/sb22/test$ time scriba bench.sb
50000

real 0m0.133s
user 0m0.125s
sys 0m0.008s
jrs@laptop:~/sb/sb22/test$


Here is the new BaCon 3.3 version on my laptop.

Code: [Select]
BLA$ = ""

FOR i = 1 TO 50000
    BLA$ = BLA$ & "@"
NEXT
PRINT LEN(BLA$),"\n"


jrs@laptop:~/BaCon/bacon-3.3$ bacon bench.bac
Converting 'bench.bac'... done, 7 lines were processed in 0.005 seconds.
Compiling 'bench.bac'... cc -c bench.bac.c
cc -o bench bench.bac.o -lbacon -lm
Done, program 'bench' ready.
jrs@laptop:~/BaCon/bacon-3.3$ time ./bench
50000

real 0m0.229s
user 0m0.220s
sys 0m0.004s
jrs@laptop:~/BaCon/bacon-3.3$ bacon -v

BaCon version 3.3 beta - (c) Peter van Eerten - MIT License.

jrs@laptop:~/BaCon/bacon-3.3$


Quote from: Peter BaCon

You can try to make me look ridiculous, but you know d*** well you have modified the actual benchmark program (which is clearly mentioned in the above posts, multiple times).

And accidentally, with this change, all of a sudden your advertised ScriptBasic interpreter seems to be 'faster'.

Please abstain from deceptive posts like this and try to be clear and straight forward.

Thank you,
Peter

PS I am not using the 32-bit version as I am not using ScriptBasic at all - not for a long time, and for reasons you already know.

Making this comparison got me ban on the BaCon forum but lets move on. James Fuller posted a BCX derivative which pre-dimensions a string and populates it with a g_string_append_c() function call.

Quote
Peter,
Is this cheating :) Using my new UbxBasic and GStrings ?

James

Code: [Select]
$ONEXIT "~/UbxBasic/glib_build.sh $FILE$ -s"
$GLIB
Raw As GString Ptr gs
gs  = g_string_sized_new(20001)
Dim i As Integer
For i = 1 To 200000
gs = g_string_append_c(gs,ASC("@"))
Next i
Print Right$(gs$->str,10)


james@james-DX4870:~/UbxBasic/examples/jcf/strwork$ time ./t02
@@@@@@@@@@

real 0m0.003s
user 0m0.000s
sys 0m0.000s


Here is the Script BASIC equivalent.

Code: Script BASIC
  1. PRINT LEN(STRING(20000,"@")),"\n"
  2.  


jrs@laptop:~/sb/sb22/test$ time scriba jfstring.sb
20000

real   0m0.003s
user   0m0.000s
sys   0m0.003s
jrs@laptop:~/sb/sb22/test$


Keep in mind Script BASIC is an interpreter that must be loaded from disk and initialized before loading the script, parsing, tokenizing and running it. This all happens before the string is being built which is the point of this benchmark. The compiled (optimized) C example just focuses on appending a character to per dimensioned string.
« Last Edit: February 07, 2016, 12:05:45 AM by John »