Page 1 of 2

Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 9:34 am
by zxretrosoft
Hi Friends,
You might be interested.
I made a simple algorithm, intentionally brute force with CASE.

The task is: The algorithm must find the order on which the LWK3724 code is located. Start numbering AAA0000, AAA0001, AAA0002... etc.
The alphabet is classic. A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z.

The correct answer is: 80183725.

I did exactly the same algorithm in 24 languages. Here are the results, for what time (in seconds) each language found this number on the same PC.

It looks like Pure is not at this very convenient, but Spider is doing great!

P.S. It's not a complete test of languages. This is a solution to one particular example. Intentionally "example of life", not a textbook example of recursion..

Image

Here is the code in PB:

Code: Select all

Global p.i
Global x.i=-1
Global a1.i,a2.i,a3.i
Global ps1.s,ps2.s,ps3.s
Global h1.s,h2.s,h3.s
Global h.i

h1="L"
h2="W"
h3="K"
h=3724


Repeat
  
  x+1
  p+1
  
  If x>9999
    x=0
    a3+1
    If a3>25
      a3=0
      a2+1
      If a2>25
        a2=0
        a1+1
      EndIf
    EndIf
  EndIf
  
  Select a1
    Case 0
      ps1="A"
    Case 1
      ps1="B"
    Case 2
      ps1="C"
    Case 3
      ps1="D"
    Case 4
      ps1="E"
    Case 5
      ps1="F"
    Case 6
      ps1="G"
    Case 7
      ps1="H"
    Case 8
      ps1="I"
    Case 9
      ps1="J"
    Case 10
      ps1="K"
    Case 11
      ps1="L"
    Case 12
      ps1="M"
    Case 13
      ps1="N"
    Case 14
      ps1="O"
    Case 15
      ps1="P"
    Case 16
      ps1="Q"
    Case 17
      ps1="R"
    Case 18
      ps1="S"
    Case 19
      ps1="T"
    Case 20
      ps1="U"
    Case 21
      ps1="V"
    Case 22
      ps1="W"
    Case 23
      ps1="X"
    Case 24
      ps1="Y"
    Case 25
      ps1="Z"
  EndSelect
  
  Select a2
    Case 0
      ps2="A"
    Case 1
      ps2="B"
    Case 2
      ps2="C"
    Case 3
      ps2="D"
    Case 4
      ps2="E"
    Case 5
      ps2="F"
    Case 6
      ps2="G"
    Case 7
      ps2="H"
    Case 8
      ps2="I"
    Case 9
      ps2="J"
    Case 10
      ps2="K"
    Case 11
      ps2="L"
    Case 12
      ps2="M"
    Case 13
      ps2="N"
    Case 14
      ps2="O"
    Case 15
      ps2="P"
    Case 16
      ps2="Q"
    Case 17
      ps2="R"
    Case 18
      ps2="S"
    Case 19
      ps2="T"
    Case 20
      ps2="U"
    Case 21
      ps2="V"
    Case 22
      ps2="W"
    Case 23
      ps2="X"
    Case 24
      ps2="Y"
    Case 25
      ps2="Z"
  EndSelect
  
  Select a3
    Case 0
      ps3="A"
    Case 1
      ps3="B"
    Case 2
      ps3="C"
    Case 3
      ps3="D"
    Case 4
      ps3="E"
    Case 5
      ps3="F"
    Case 6
      ps3="G"
    Case 7
      ps3="H"
    Case 8
      ps3="I"
    Case 9
      ps3="J"
    Case 10
      ps3="K"
    Case 11
      ps3="L"
    Case 12
      ps3="M"
    Case 13
      ps3="N"
    Case 14
      ps3="O"
    Case 15
      ps3="P"
    Case 16
      ps3="Q"
    Case 17
      ps3="R"
    Case 18
      ps3="S"
    Case 19
      ps3="T"
    Case 20
      ps3="U"
    Case 21
      ps3="V"
    Case 22
      ps3="W"
    Case 23
      ps3="X"
    Case 24
      ps3="Y"
    Case 25
      ps3="Z"
  EndSelect
  
Until h1=ps1 And h2=ps2 And h3=ps3 And h=x

Debug(p)

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 9:44 am
by wilbert
zxretrosoft wrote:I did exactly the same algorithm in 21 languages. Here are the results, for what time (in seconds) each language found this number on the same PC.

It looks like Pure is not at this very convenient, but Spider is doing great!
Did you test with PB debugger disabled ?

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 10:11 am
by User_Russian

Code: Select all

DisableDebugger

Global p.i
Global x.i=-1
Global a1.i,a2.i,a3.i
Global ps1.s{1},ps2.s{1},ps3.s{1}

#h1="L"
#h2="W"
#h3="K"
#h=3724

t = ElapsedMilliseconds()

Repeat
  
  x+1
  p+1
  
  If x>9999
    x=0
    a3+1
    If a3>25
      a3=0
      a2+1
      If a2>25
        a2=0
        a1+1
      EndIf
    EndIf
  EndIf
  
  Select a1
    Case 0
      ps1="A"
    Case 1
      ps1="B"
    Case 2
      ps1="C"
    Case 3
      ps1="D"
    Case 4
      ps1="E"
    Case 5
      ps1="F"
    Case 6
      ps1="G"
    Case 7
      ps1="H"
    Case 8
      ps1="I"
    Case 9
      ps1="J"
    Case 10
      ps1="K"
    Case 11
      ps1="L"
    Case 12
      ps1="M"
    Case 13
      ps1="N"
    Case 14
      ps1="O"
    Case 15
      ps1="P"
    Case 16
      ps1="Q"
    Case 17
      ps1="R"
    Case 18
      ps1="S"
    Case 19
      ps1="T"
    Case 20
      ps1="U"
    Case 21
      ps1="V"
    Case 22
      ps1="W"
    Case 23
      ps1="X"
    Case 24
      ps1="Y"
    Case 25
      ps1="Z"
  EndSelect
  
  Select a2
    Case 0
      ps2="A"
    Case 1
      ps2="B"
    Case 2
      ps2="C"
    Case 3
      ps2="D"
    Case 4
      ps2="E"
    Case 5
      ps2="F"
    Case 6
      ps2="G"
    Case 7
      ps2="H"
    Case 8
      ps2="I"
    Case 9
      ps2="J"
    Case 10
      ps2="K"
    Case 11
      ps2="L"
    Case 12
      ps2="M"
    Case 13
      ps2="N"
    Case 14
      ps2="O"
    Case 15
      ps2="P"
    Case 16
      ps2="Q"
    Case 17
      ps2="R"
    Case 18
      ps2="S"
    Case 19
      ps2="T"
    Case 20
      ps2="U"
    Case 21
      ps2="V"
    Case 22
      ps2="W"
    Case 23
      ps2="X"
    Case 24
      ps2="Y"
    Case 25
      ps2="Z"
  EndSelect
  
  Select a3
    Case 0
      ps3="A"
    Case 1
      ps3="B"
    Case 2
      ps3="C"
    Case 3
      ps3="D"
    Case 4
      ps3="E"
    Case 5
      ps3="F"
    Case 6
      ps3="G"
    Case 7
      ps3="H"
    Case 8
      ps3="I"
    Case 9
      ps3="J"
    Case 10
      ps3="K"
    Case 11
      ps3="L"
    Case 12
      ps3="M"
    Case 13
      ps3="N"
    Case 14
      ps3="O"
    Case 15
      ps3="P"
    Case 16
      ps3="Q"
    Case 17
      ps3="R"
    Case 18
      ps3="S"
    Case 19
      ps3="T"
    Case 20
      ps3="U"
    Case 21
      ps3="V"
    Case 22
      ps3="W"
    Case 23
      ps3="X"
    Case 24
      ps3="Y"
    Case 25
      ps3="Z"
  EndSelect
  
Until #h1=ps1 And #h2=ps2 And #h3=ps3 And #h=x

t = ElapsedMilliseconds() - t

MessageRequester("", "Time "+StrF(t/1000, 3)+~" seconds\nResult "+Str(p))

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 10:20 am
by Kiffi
That makes me sceptical:

Image

Greetings ... Peter

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 10:24 am
by zxretrosoft
@User_Russian
Thanks a lot for correction! It is significantly faster. Fixed :wink:

@Kiffi
It also occurred to me ... But I do not know what to do with it.

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 10:38 am
by Kiffi
@zxretrosoft

The SpiderBasic code is transpiled to JavaScript. For this reason SpiderBasic cannot be faster than JavaScript.

Greetings ... Peter

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 10:47 am
by zxretrosoft
Yes, that's right but this is very complicated.

To JS translates different languages. SpiderBasic, Monkey, CerberusX... But only from SpiderBasic it's been measured this fast. That's why I kept the name SpiderBasic (and not JS).

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 10:50 am
by NicTheQuick
It is impossible that Spiderbasic is faster than Go, C, C++, C# except your coding is bad.
But I also don't understand that Purebasic code and the test itself. Why bruteforcing a 3 letter combination and a a number? And why using these big Selects when it is much easier and faster with Chr(). And why using fixed one character strings instead of the Character type? Is this a standardized test?

Why not writing the test this way:

Code: Select all

DisableDebugger

EnableExplicit

Global p.i = 1
Global x.i = 0
Global ps1.c = 'A', ps2.c = 'A', ps3.c = 'A'

#h1 = 'L'
#h2 = 'W'
#h3 = 'K'
#h  = 3724

Define.i t = ElapsedMilliseconds()

While ps1 <> #h1 Or ps2 <> #h2 Or ps3 <> #h3 Or #h <> x
	
	x + 1
	p + 1
	
	If x > 9999
		x = 0
		ps3 + 1
		If ps3 > 'Z'
			ps3 = 'A'
			ps2 + 1
			If ps2 > 'Z'
				ps2 = 'A'
				ps1 + 1
			EndIf
		EndIf
	EndIf
Wend

t = ElapsedMilliseconds() - t

Define.s Result
Result = "Time: " + StrF(t / 1000, 3) + ~" seconds\n" +
         "Result: " + Str(p) + ~"\n" +
         "Found: " + Chr(ps1) + Chr(ps2) + Chr(ps3) + RSet(StrU(x), 4, "0")

MessageRequester("", Result)
This needs 0.154 seconds on my machine.

Edit: And another point: Which Javascript engine and which browser did you use?

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 11:00 am
by zxretrosoft
Of course, there is a much better way to write this code. You can write e.g. just a formula:
11*26*26*10.000 + 22*26*10.000 + 10*10.000 + 3725

However, I deliberately chose a code that is more complex with several CASEs, atp. And exactly the same code is to be written in all languages.

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 11:05 am
by NicTheQuick
In my opinion, code should be tailored to the programming language and not translated 1:1 and then compiled. It's like translating between different languages. Not only the syntax is different, but also the grammar and the formulations.

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 11:17 am
by zxretrosoft
You are right. But

1. This code is so simple that basically it can not be done otherwise.
2. Most people have their own style. E.g. I'm programming like Pure like C#... It's wrong, but it's commonplace in practice. So I'm interested in how successful languages are in one and the same style.

EDIT:
It's not a competition:
Write the best technique in a specific language for this example.
But use the same (though stupid) technique in different languages.
Result: You will learn what language is better for your technique. Not what language is the fastest.

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 11:47 am
by NicTheQuick
Okay. If you wanna see it this way around you can do that.

But nevertheless: You should also mention which Javascript engine and browser you are using for your tests. IE, Firefox and Chrome are very different and because they are JIT compilers they maybe able to analyse your code and simplify it because it has a static input and is deterministic. So the output will always be the same.

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 12:13 pm
by Trond
You need to disable the debugger from the menu when doing speed tests.

DisableDebugger isn't enough.

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 12:55 pm
by Dude
Trond wrote:You need to disable the debugger from the menu when doing speed tests.

DisableDebugger isn't enough.
They don't do the same thing?

Re: Speed of Pure & Spider comparsion

Posted: Fri Jun 15, 2018 1:18 pm
by NicTheQuick
No.