Speed comparison

Post Reply
User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Speed comparison

Post by Dutchman »

DrChip is a very active member of the forum on the other app: 'Basic!'
He has made a "Graphic bench mark test".
See http://appball.com/basic/viewtopic.php?f=7&t=4730
In order to compare the two 'basic' apps, I have adapted that program to run on Smart Basic.

Code: Select all

' Graphic bench mark test
' by DrChip » 01 Apr 2014, 17:30
' developed for the app 'Basic!'
' adapted for Smart Basic by Dutchman
' original 'Basic!' lines are commented out with '***

REM Benchmark - Dots per Second
REM iPhone 5s / 7.1 / 3.5.3
REM comment out the test your not using
REM is random not random still? 
REM look at the triangles grouped

time=1000 '*** time = 1 'one second
test = 1 '1 point, 2 circle, 3 triangle

'*** prepare graphics for Smart Basic
GRAPHICS
GRAPHICS CLEAR 0,0,0
'*** end graphics initialisation for Smart Basic

loop:
DRAW COLOR RND(1),RND(1),RND(1) '*** COLOR RND*255,RND*255,RND*255
t=TIMER() '***t=TickCount
WHILE TIMER()-t<=time '*** WHILE TickCount-t<=time 
    x1=RND(1)*Screen_Width() '*** x1=RND*ScreenWidth
    y1=RND(1)*Screen_Height() '*** y1=RND*ScreenHeight
    IF test = 1 AND g=0 THEN
        DRAW PIXEL x1,y1 '***POINT x1,y1,1
        g=1
    END IF 
    IF test = 2 AND g=0 THEN 
        DRAW CIRCLE x1,y1 SIZE 1 '*** CIRCLE x1,y1,1
        g=1
    END IF
/* Function TRIANGLE is not available in Smart Basic
    IF test = 3 AND g=0 THEN
        x2=RND*ScreenWidth
        y2=RND*ScreenHeight 
        x3=RND*ScreenWidth
        y3=RND*ScreenHeight 
        TRIANGLE x1,y1,x2,y2,x3,y3
        g=1
    END IF 
*/
    g= 0
    d=d+1
END WHILE '*** WEND
GRAPHICS CLEAR 0,0,0'*** CLS 
DRAW COLOR 1,1,1 '*** COLOR 1,1,1
DRAW TEXT "Current DPS: "&STR$(d,"#") AT 10,10 '*** DRAWTEXT "Current DPS: " + STR$(d), 0,0
d=0
GOTO loop
Result:
IF test =1 (pixels) THEN Smart Basic is 12.7 times faster then Basic!
IF test=2 (circles) THEN Smart Basic is 5.6 times faster then Basic!
test=3 could not be compared because Smart Basic has no TRIANGLE function (made for '3D' drawing).
Part of the speed difference is explained by the fact that Basic! draws in anti-aliasing mode whereas Smart Basic draws at the coordinates unprocessed.
That can not explain the total difference. So champagne and flowers for Mr. K. :D :D
I have added the top left corner of the screenshots.
The names of the pictures explain the origin.
Attachments
circles in Smart Basic
circles in Smart Basic
circles Smart Basic.png (39.29 KiB) Viewed 2571 times
circles in Basic!
circles in Basic!
circles Basic!.png (13.27 KiB) Viewed 2571 times
pixels in Smart Basic
pixels in Smart Basic
pixels Smart Basic.png (37.18 KiB) Viewed 2571 times
pixels in Basic!
pixels in Basic!
pixels Basic!.png (13.29 KiB) Viewed 2571 times

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Speed comparison

Post by Dutchman »

I have posted the results also on the other forum. See http://appball.com/basic/viewtopic.php?f=7&t=4730
There is a chance that it will be removed ;)

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Speed comparison

Post by Mr. Kibernetik »

Thank you very much, Dutchman, for this interesting test!

I have some comments.
1. Actually smart BASIC can draw triangles. It can draw n-gons. Please check DRAW POLY command.
2. Also I suppose that ScreenWidth is a system constant in Basic!, and you use function SCREEN_WIDTH() in sB program. Technically it is not correct - it's better to assign screen size to variables and use variables inside cycle - it will be even faster.
3. I don't know what means that "Basic! draws in anti-aliasing mode", but I have to say that sB draws graphics antialiased. And sB uses not integer but float coordinates (except pixels which are physically integer).
4. Also your program is not working correctly on retina device - please see my version of code how it is corrected.

So, this is my mod of your test:

Code: Select all

' Graphic bench mark test
' by DrChip » 01 Apr 2014, 17:30
' developed for the app 'Basic!'
' adapted for Smart Basic by Dutchman
' original 'Basic!' lines are commented out with '***

REM Benchmark - Dots per Second
REM iPhone 5s / 7.1 / 3.5.3
REM comment out the test your not using
'*** REM is random not random still? 
'*** REM look at the triangles grouped

time=1000 '*** time = 1 'one second
test = 1 '1 point, 2 circle, 3 triangle

'*** prepare graphics for Smart Basic
GRAPHICS
'*** end graphics initialisation for Smart Basic

ScreenWidth=screen_width()
ScreenHeight=screen_height()
if test=1 then
   ScreenWidth *= screen_scale()
   ScreenHeight *= screen_scale()
end if
dim xt(3),yt(3)
option base 1

loop:
DRAW COLOR RND(1),RND(1),RND(1) '*** COLOR RND*255,RND*255,RND*255
t=TIMER() '***t=TickCount
WHILE TIMER()-t<=time '*** WHILE TickCount-t<=time 
    x1=RND(1)*ScreenWidth '*** x1=RND*ScreenWidth
    y1=RND(1)*ScreenHeight '*** y1=RND*ScreenHeight
    IF test = 1 AND g=0 THEN
        DRAW PIXEL x1,y1 '***POINT x1,y1,1
        g=1
    END IF 
    IF test = 2 AND g=0 THEN 
        DRAW CIRCLE x1,y1 SIZE 1 '*** CIRCLE x1,y1,1
        g=1
    END IF
    IF test = 3 AND g=0 THEN
        xt(1)=x1
        yt(1)=y1
        xt(2)=RND(1)*ScreenWidth '*** x2=RND*ScreenWidth
        yt(2)=RND(1)*ScreenHeight '*** y2=RND*ScreenHeight
        xt(3)=RND(1)*ScreenWidth '*** x3=RND*ScreenWidth
        yt(3)=RND(1)*ScreenHeight '*** y3=RND*ScreenHeight
        DRAW POLY xt,yt '*** TRIANGLE x1,y1,x2,y2,x3,y3
        g=1
    END IF 
    g= 0
    d=d+1
END WHILE '*** WEND
GRAPHICS CLEAR 0,0,0'*** CLS 
DRAW COLOR 1,1,1 '*** COLOR 1,1,1
DRAW TEXT "Current DPS: "&STR$(d,"#") AT 10,10 '*** DRAWTEXT "Current DPS: " + STR$(d), 0,0
d=0
GOTO loop

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Speed comparison

Post by Dutchman »

1. Basic! also has a function to draw polygons:
SHAPE num_points, point_xs, point_ys [, line_width] -- Draw a custom shape defined by lines. Lines are represented by two arrays: point_xs and point_ys. Shape is filled when line_width <= 0 (which is a default).
The TRIANGLE function has been added to improve speed with '3D'-drawing.
2. Screenwidth and Screenheight are functions in Basic!
ScreenWidth and ScreenHeight -- Functions that return screen dimentions.
Example: LINE 0, 0, ScreenWidth, ScreenHeight
3. I was referring to the high speed of drawing pixels. Indeed SB draws single pixels, whereas Basic! draws anti-aliased dots with the POINT command
POINT x, y [, point_size] — Draw a point. Default size is 1 (pixel)
I have added enlarged pictures of the pixel test. Although the default size in Basic! is 1 pixel, all displayed dots are larger.
Aliasing occurs in sampled signals if the bandwidth of the signal exceeds half the sample-frequency. It has to be noted that frequencies in this context are in the two-dimensional spatial domain (cycles per picture-width and cycles per picture-height) rather than the time-domain (cycles per second).
In order to prevent aliasing, the signal-bandwidth has to be limited. As a consequence the smallest dot will cover at least two samples (pixels) in horizontal AND vertical direction, unless the dot is positioned exactly on the sample-position which will almost never occur if the dots are positioned at random.
Maybe SB should be extended with a 'DRAW DOT' command in order to be able to draw antialiased figures point by point.
4. I have an old-fashioned iPad-1 :D No retina display, so I can not test your corrections
Attachments
enlarged pixels smart basic.png
enlarged pixels smart basic.png (7.6 KiB) Viewed 2559 times
enlarged pixels Basic!.png
enlarged pixels Basic!.png (7.5 KiB) Viewed 2559 times

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Speed comparison

Post by Mr. Kibernetik »

I also have old iPad :D but in iOS Simulator I can test any kind of iOS device :ugeek:
So if someone will run this test on his retina device he will see the difference...

Well, does this mean that Basic! actually cannot draw pixels? Because on retina devices each point (measuring size 1x1 in coordinates) consists of 4 (!) pixels (2x2 pixels for each single point). This means that sB has real access to any pixel even on retina screen (this is why SCREEN_SCALE() function is necessary when working with pixels whereas all other drawing commands use points instead of pixels). Shall we exclude Basic!'s pixel testing from this speed test because its "pixels" are not pixels but just small polygons? :lol:

Very interesting, what is '3D'-drawing in Basic!? And why TRIANGLE command is needed? If to "speed up" something then using "non-optimized" sB command DRAW POLY instead is fine. So can we say that "sB can not draw 'optimized in a Basic! way' triangles" instead of "sB can not draw triangles" and just use "non-optimized" DRAW POLY command instead?

What about "just drawing single points" (which are not pixels but antialiased dots) one can use filled circles or filled polygons to get whatever point he needs. Not?

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Speed comparison

Post by Dutchman »

I think that Basic! also can draw 'pixels', but than at least the coordinates should be rounded to integers. I should try that, but I am no longer interested in programming Basic!. The forum however is still interesting.
It would be fair to exclude the pixel test from speed comparison. Still we have a difference of a factor 5, almost 6 :!:

In '3D' drawing, curved surfaces are constructed by concatenating triangles.
'DrChip' is a professional programmer (looking for a job) and in my opinion an expert on '3D'-programming.
An example is the program 'Simple flag with a T'. See http://appball.com/basic/viewtopic.php?f=7&t=4737
I have added one of his screenshots.
A short tutorial by DrChip is found on http://appball.com/basic/viewtopic.php?f=11&t=594
The request for a TRIANGLE function was initiated by him or his son 'digit'.
The speed (of the examples) however is still insufficient for complex shapes.

I agree that the command FILL CIRCLE covers the point draw item.
Attachments
Wobbling flag constructed with triangles.
Wobbling flag constructed with triangles.
flag with T.jpg (60.43 KiB) Viewed 2559 times

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Speed comparison

Post by Henko »

dr. chip produces a code snippet almost every day, but they are all in the category "funny graphics". And indeed it is (almost?) impossible to produce any serious application in Basic!, for reasons earlier mentioned. The available functionality simply forbids it. It still is a "toy" in stead of a "tool".

Post Reply