Main Menu

Bench Marking code of some type

Started by kevin, June 18, 2018, 10:59:52 AM

Previous topic - Next topic

kevin

 Bench Marking code of some type

  Here's is some type of benchmark code by Zdeněk Šimek

PlayBASIC Code: [Select]
x=-1

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

repeat

x=x+1
p=p+1

if x>9999
x=0
a3=a3+1
if a3>25
a3=0
a2=a2+1
if a2>25
a2=0
a1=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"
Login required to view complete source code


kevin

#1
  I'm not to sure what this is testing, but here's a version that uses a On Variable goto JUMP TABLE implication as comparing Switch from C/C++ to Select/Case BASIC isn't the same structure.

 On my laptop (which on has V1.64P4 on it) this about 66% faster than Select/Case version, which is about what I would expect, you can tweak the logic but that's for another day.


BenchMark Version 02 - Jump Tables
PlayBASIC Code: [Select]
; PROJECT : BenchMark Version 02 - Jump Tables
; AUTHOR : Kevin Picone
; CREATED : 20/06/2018
; EDITED : 20/06/2018
; ---------------------------------------------------------------------


; ---------------------------------------------------------------------

StartTime=Timer()

print "Benchmark started Jump Table Version"
sync

x=-1

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

repeat

x=x+1
p=p+1

if x>9999
x=0
a3=a3+1
if a3>25
a3=0
a2=a2+1
if a2>25
a2=0
a1=a1+1
endif
endif
endif

on A1 goto A1_0,A1_1,A1_2,A1_3,A1_4,A1_5,A1_6,A1_7,A1_8,A1_9,A1_10,A1_11,A1_12,A1_13,A1_14,A1_15,A1_16,A1_17,A1_18,A1_19,A1_20,A1_21,A1_22,A1_23,A1_24,A1_25
goto A1_Done

A1_0:
ps1$ = "A"
goto A1_Done

A1_1:
ps1$ = "B"
goto A1_Done

A1_2:
ps1$ = "C"
goto A1_Done

A1_3:
ps1$ = "D"
goto A1_Done

A1_4:
ps1$ = "E"
goto A1_Done

A1_5:
ps1$ = "F"
goto A1_Done

A1_6:
ps1$ = "G"
goto A1_Done

A1_7:
ps1$ = "H"
goto A1_Done

A1_8:
ps1$ = "I"
goto A1_Done

A1_9:
ps1$ = "J"
goto A1_Done

A1_10:
ps1$ = "K"
goto A1_Done

A1_11:
ps1$ = "L"
goto A1_Done

A1_12:
ps1$ = "M"
goto A1_Done

A1_13:
ps1$ = "N"
goto A1_Done

A1_14:
ps1$ = "O"
goto A1_Done

A1_15:
ps1$ = "P"
goto A1_Done

A1_16:
ps1$ = "Q"
goto A1_Done

A1_17:
ps1$ = "R"
goto A1_Done

A1_18:
ps1$ = "S"
goto A1_Done

A1_19:
ps1$ = "T"
goto A1_Done

A1_20:
ps1$ = "U"
goto A1_Done

A1_21:
ps1$ = "V"
goto A1_Done

A1_22:
ps1$ = "W"
goto A1_Done

A1_23:
ps1$ = "X"
goto A1_Done

A1_24:
ps1$ = "Y"
goto A1_Done

A1_25:
ps1$ = "Z"
A1_Done:


on A2 goto A2_0,A2_1,A2_2,A2_3,A2_4,A2_5,A2_6,A2_7,A2_8,A2_9,A2_10,A2_11,A2_12,A2_13,A2_14,A2_15,A2_16,A2_17,A2_18,A2_19,A2_20,A2_21,A2_22,A2_23,A2_24,A2_25
Login required to view complete source code



BenchMark Version 01 - Original Select /Case Version

PlayBASIC Code: [Select]
; PROJECT : BenchMark Version 01
; AUTHOR : Kevin Picone
; CREATED : 20/06/2018
; EDITED : 20/06/2018
; ---------------------------------------------------------------------


; ---------------------------------------------------------------------

StartTime=Timer()

print "Benchmark started Original Version"
sync

x=-1

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

repeat

x=x+1
p=p+1

if x>9999
x=0
a3=a3+1
if a3>25
a3=0
a2=a2+1
if a2>25
a2=0
a1=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

Login required to view complete source code

zxretrosoft

Hi Kevin,
it's not even a complex "benchmarking," but it's one practical task that is solved by the same way (ie the same algorithm 1:1) in different languages on the same PC.
Your solution is much smarter and faster. In each language, this task can be optimized differently. But it was about using SELECT / CASE and strings. And keep the algorithm.

In other words. 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. For your programming style. Not what language is the fastest  ;)
I apologize in advance for bad English