Oxygen Basic

Programming => Example Code => General => Topic started by: JRS on April 12, 2014, 08:14:59 AM

Title: The integer Mandelbrot bench
Post by: JRS on April 12, 2014, 08:14:59 AM
Quote
Scriba           681.86 seconds   ??       scriptbasic.com

Hi Ed,

Would you mind posting the Script BASIC code for your benchmark? I would like to try your code on Windows 7 as a 64 bit application. (not in the 32 bit emulator all the other tests were run under)  Are there any other BASIC languages on your list able to run native 64 bit on your box?

Quote
As they say, take this with a grain of salt!

I'm happy you added that disclaimer because your Script BASIC results are off by ~ 680 seconds.

I would appreciate if you would correct the errors in your post on BP.org.

1. Change Scriba to Script BASIC.

2. The open source project site for Script BASIC is www.scriptbasic.org not Peter's static archive of his early work on the scriptbasic.com site. You are pointing people to OLD code that more than likely no longer works on todays OS platforms.

3. The ?? should be replaced with ANSI/ISO C.

A bit further down in the post ...

Quote
Scriba         BASIC interpreter

Please change to ...

Script BASIC - Embeddable multi-threaded scripting API with a traditional BASIC enhanced syntax.

Thanks in advance for correcting these errors.

John Spikowski
Script BASIC Project Manager (since 2006)

@Mike - I didn't see a FBSL entry in Ed's list.

Title: Re: The integer Mandelbrot bench
Post by: Ed Davis on April 19, 2014, 02:20:48 AM
Quote
Scriba           681.86 seconds   ??       scriptbasic.com

Hi Ed,

Would you mind posting the Script BASIC code for your benchmark? I would like to try your code on Windows 7 as a 64 bit application. (not in the 32 bit emulator all the other tests were run under)  Are there any other BASIC languages on your list able to run native 64 bit on your box?

I'm happy you added that disclaimer because your Script BASIC results are off by ~ 680 seconds.


Nope, I get about the same time every time I run the benchmark.  While having lots of neat things to offer, it is somewhat slow, compared to other interpreters.  At least on my machine.

The code is almost identical to that used for the other BASIC interpreters.  Here it is:

Code: [Select]
accum = 0
count = 0
while count < 1545
    left_edge   = -420
    right_edge  =  300
    top_edge    =  300
    bottom_edge = -300
    x_step      =  7
    y_step      =  15

    max_iter    =  200

    y0 = top_edge
    while y0 > bottom_edge
        x0 = left_edge
        while x0 < right_edge
            y = 0
            x = 0
            the_char = 32
            x_x = 0
            y_y = 0
            i = 0
            while i < max_iter and x_x + y_y <= 800
                x_x = (x * x) \ 200
                y_y = (y * y) \ 200
                if x_x + y_y > 800 then
                    the_char = 48 + i
                    if i > 9 then
                        the_char = 64
                    end if
                else
                    temp = x_x - y_y + x0
                    if (x < 0 and y > 0) or (x > 0 and y < 0) then
                        y = (-1 * (-1 * x * y) \ 100) + y0
                    else
                        y = (x * y \ 100) + y0
                    end if
                    x = temp
                end if

                i = i + 1
            wend
            accum = accum + the_char

            x0 = x0 + x_step
        wend

        y0 = y0 - y_step
    wend

    if count % 300 = 0 then
        print accum, " "
    end if

    count = count + 1
wend

print accum

Title: Re: The integer Mandelbrot bench
Post by: Mike Lobanovsky on April 19, 2014, 04:41:36 AM
@Mike - I didn't see a FBSL entry in Ed's list.

Hehe John,

I am not a retro-BASIC type of guy so I am not registered at that forum. Yet I do skim through their content occasionally to amuse myself with funny things that are happening there from time to time. :)
Title: Re: The integer Mandelbrot bench
Post by: JRS on April 19, 2014, 09:04:20 AM
Quote from: Ed Davis
While having lots of neat things to offer, it is somewhat slow, compared to other interpreters

Thanks Ed for posting the code. I see now where the problem is. You didn't use the Mandelbrot iterator function in SB. My test with well over twice the number of iterations per pixel results in a just over a second in execution time.  (yours = 200, this example = 510 iterations per pixel)

(http://files.allbasic.info/ScriptBasic/gfx/sbgfxu64_mandelbrot2.png)

Code: [Select]
' ScriptBasic GFX - Mandelbrot

IMPORT gfx.inc

s = gfx::Window(640,480,"ScriptBasic GFX Mandelbrot")
ts = gfx::Time()
FOR y = 0 TO 479
  FOR x = 0 TO 639
    cx = (x - 320) / 120
    cy = (y - 240) / 120
    rit = gfx::Mandelbrot(cx, cy, 510)
    gfx::PixelRGBA s, x, y, rit * 12, rit * 8, rit * 4, 255
  NEXT
NEXT
te = gfx::Time()
gfx::stringColor s, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0x000000ff
gfx::Update
WHILE gfx::KeyName(1) <> "+escape"
WEND
gfx::Close

I could convert the above to return the results you're looking for but I don't see the point just to prove you're mistaken about Script BASIC being slow. Script BASIC has one of the best extension APIs going which uses C BASIC for ease of use.

I have noticed that Script BASIC WHILE/WEND is noticeably slower then FOR/NEXT. I try to avoid using WHILE other than for small loops.

Thanks for your efforts and if you could correct the post(s) on BP.org and your misleading statements, that would be great!

 
Title: Re: The integer Mandelbrot bench
Post by: Aurel on April 19, 2014, 02:16:57 PM
John
How you espect that we can try your SB gfx mandelbrot example when
scriba or scribaw ( win32) version not work by drag & drop source file
into interpreter exe.
I only see that output window flash and close  :o
I look into allbasic forum and into scriptbasic forum and download latest release
but nothing ?

PS.heh even i can force my toy interpreter with mandelbrot function which
he can execute in less than a second
Title: Re: The integer Mandelbrot bench
Post by: JRS on April 19, 2014, 02:45:48 PM

Still running XP ?

SCRIBA is a console mode interpreter example of the Script BASIC API. It allows redirection which comes in handy when used in a batch/shell script. I'm not aware of any other console mode languages that allow drag and drop functionality. The scribaw (now called sbiup.exe) is a Windows application and has no console support. It still requires you to pass the name of the script you are going to run as an argument. I hope that cleared things up for you.

Quote
I only see that output window flash and close  :o
I look into allbasic forum and into scriptbasic forum and download latest release
but nothing ?

Try scriba -d alpha_circles.sb and see if it shows a missing dependency. Are you running SB 2.2? You could always insert a PRINT "Got Here\n debug statement in the code and see how far you get. Script BASIC wouldn't even start if the program had errors in it. It sounds like you don't have the SDL_gfx.dll in the search path so Windows can find it. Is your scriba.conf file working? What do you see when you do a scriba -D?
Title: Re: The integer Mandelbrot bench
Post by: Mike Lobanovsky on April 19, 2014, 06:09:32 PM
John,

I'm also running XP now as you may see from my current IP data on your server and I'm planning to do so for a long time to come. While my dev platform is Windows 7 since April 8, I'm going to support XP in my products as long as it doesn't interfere with the main functionality of FBSL. BTW such support is still a must in many a contract that I work under as a freelancer.

XP is not a curse. It's been my very good companion for many years and I'm sorry to see it go. I saw only one crash of XP in over six years and that was caused by a broken boot sector in one of my older hard drives.

Happy Easter! :)
Title: Re: The integer Mandelbrot bench
Post by: Aurel on April 19, 2014, 09:58:46 PM
John
You can see what i have in SB2.2 folder on C disk and nothing work.
And why not work by drag & drop ?
is this really to tuff to implement that for you? ,or is this impossibile ?

 And yes what is wrong if some of us use XP.
I will try to modify my ASciEdit to work with SB2.2 and then i will try...

.
Title: Re: The integer Mandelbrot bench
Post by: JRS on April 19, 2014, 10:09:45 PM
Q. After opening a Windows console and sitting at the C:> prompt, what happens when you type in scriba -D?

A. If Windows says that scriba isn't a valid command, you didn't add the Script BASIC bin directory in your search path. If scriba says it can't find its configuration file with the -D option then that needs to be set up.

I wrote a fairly detail manual install for Script BASIC 2.2 on the www.scriptbasic.org/forum (downloads - sticky 2.2 release) that should be simple enough for anyone to understand even if English isn't your primary language.

@Mike - Maybe I'm too close to SB to see what Aurel's issue is. Have you had any problem getting Script BASIC working on Windows?
Title: Re: The integer Mandelbrot bench
Post by: Aurel on April 19, 2014, 10:21:47 PM
John
SB interpreter ( even is console based) must respond on Shell api
shellExecute, so when i modify my editor i will try..ok
Title: Re: The integer Mandelbrot bench
Post by: JRS on April 19, 2014, 10:24:01 PM
Why add another layer to your problem. Are you afraid of the console window? Please try the test I asked you to and let me know what happens.
Title: Re: The integer Mandelbrot bench
Post by: Mike Lobanovsky on April 19, 2014, 10:51:06 PM
@Aurel:

1. How come your screenshot shows two files called "scriba.conf" in one and the same directory? :o Go to the Windows Explorer settings (they should be somewhere near your main menu settings on right-clicking the Start orb IIRC) and make it show filename extensions and hidden and system files and everything else. It's supposed to be a coder's PC, after all, not a lamer's one. ;)

2. No, ShellExecute() will only work if:

2.1. The ".sb" document's MIME type is bound with the Scribaw executable.

2.2. All the paths for the SriptBASIC installation are properly written to the Windows environment variables.

2.3. ScriptBASIC doesn't require special or particular options to launch a .sb script for execution.

3. Try to do what John says in the following sequence:

3.1. Copy your test script to the C:\SB22b2_Win32\bin directory.

3.2. Open up your console.

3.3. Type "c:" then type "cd c:\sb22b2_win32\bin". This will make this directory your working directory. Simple browsing it in the Explorer doesn't work for the console.

3.4. Type "scribaw your_test_filename_with_extension_here" to launch the script file for execution.

3.5. Always change your console path to the working directory before issuing any console commands on any platform you use.

@John:

Was I correct with the last command here? Please correct me if not. I'm currently under Mac OS X and can't check it "live".
Title: Re: The integer Mandelbrot bench
Post by: JRS on April 19, 2014, 11:03:46 PM
You're right about associating .sb with scriba.exe and running the scripts by clicking on them in explorer. Don't forget a LINE INPUT at the end of your code or the console will close as soon as the script finishes.

Lets assume Aurel installed Script BASIC in the C:\scriptbasic directory. He should use the advanced feature in System (control panel) and add C:\scriptbasic\bin to his search path. At a minimum, you need the paths to C:\scriptbasic\include\ and C:\scriptbasic\modules\ defined in the scriba.conf file. (and compiled with the scriba - k option.

The gfx.dll goes in the modules directory. The gfx.inc goes in the SB include directory and the SDL_gfx.dll goes in the Windows\System32 directory on XP (SysWOW64) if on a 64 bit Windows OS. SDL 1.2 DLL must be there as well.
Title: Re: The integer Mandelbrot bench
Post by: Mike Lobanovsky on April 19, 2014, 11:18:51 PM
Hey-hey-hey-hey!

AFAIR scriba is not the executable to run on Windows. The Windows executable is scribaw.exe and it has a proper Windows icon embedded. His Explorer, as a minimum, fails to display .exe and .bak extensions. Else how could there be two scriba.conf files in one and the same directory???

Also, his .sb documents are not bound to any executable at all - their icons are pure text files otherwise they'd show a small SB emblem on top of the paper sheet icon.

My guess is he just copied his \bin directory from some other location.

Aurel my dear, this won't work! Make a clean re-install of SB on your new "Vista" or we're gonna get real old before we see you start your first SB test… :)
Title: Re: The integer Mandelbrot bench
Post by: JRS on April 19, 2014, 11:26:27 PM
Quote
we're gonna get real old before we see you start your first SB test

 ;D  ;D

Good-Night folks.
Title: Re: The integer Mandelbrot bench
Post by: Aurel on April 20, 2014, 02:54:30 AM
Mike
this is just a proof how stupid is work with SB .
First what kind of interpreter is this DOS... ;D
and why i must always use stupid command prompt to run any example
this is more than stupid and John constantly crap how is work with script basic
easy ...
and with all this years he is not capable to create interpreter which resopnd on
drag & drop.
another what kind of install ...there is no instal only ziped file... ::)
all in all this sucks from the ground.
Title: Re: The integer Mandelbrot bench
Post by: Mike Lobanovsky on April 20, 2014, 03:35:41 AM
If somebody would help John, perhaps he could have a nice Windows installer (http://sourceforge.net/projects/nsis/) that performs .sb script file association with the main binary, installation of dynamic libraries into system directories, copying of package directory structure onto the hard disk, and registration of environment variables automatically? It can also perform automatic uninstallation of the entire package if needed... ::)

As for drag-and-drop, since his binary can read script file names from its command line, it supports Linux and Windows GUI's drag-and-drop out of the box. That's a built-in feature on both platforms and no extra programming effort is necessary. The only requirement is that there should be no extra options needed to launch the scripts for execution. Otherwise drag-and-drop won't be possible at all; however the scripts will be launchable with a double click on the script file if the .sb MIME type is associated correctly with the ScriptBASIC binary by the package installer together with any extra options the binary may need.
Title: Re: The integer Mandelbrot bench
Post by: JRS on April 20, 2014, 06:54:42 AM
@Aurel - PLEASE remove all traces of Script BASIC from your system. You are not qualified to use the language.

One must at least have the basic understanding what a Windows console is, what the DIR command does and and how to change directories with the CD command. You have refused to try any effort I have given to help you resolve your issues. You are the only person on the face of the earth that has been unable to get Script BASIC to run. Congratulations!
Title: Re: The integer Mandelbrot bench
Post by: Peter on April 20, 2014, 07:58:02 AM
Quote
@Aurel - PLEASE remove all traces of Script BASIC from your system. You are not qualified to use the language.

Lol

+1  ;D
Title: Re: The integer Mandelbrot bench
Post by: Aurel on April 20, 2014, 09:12:01 AM
LOL  +++1

Whit a :

Code: [Select]
Declare Function GetCommandLine Lib "kernel32.dll" Alias "GetCommandLineA" () as String
Is to hard to implement this api call into sciribaw ?
Title: Re: The integer Mandelbrot bench
Post by: JRS on April 20, 2014, 09:25:35 AM
Aurel,

If you want a IUP / SDL based GUI SB script to run from Windows explorer then make a standalone version by binding scriba to the script.

scribaw -Eo mypgm.exe mypgm.sb

If you don't have scriba.conf setup then all dependencies must be in the same directory as the script executable. This is why putting scriba.exe in the search path and setting up a minimal scriba.conf (SCRIBA.INI) to point to the SB include and modules directory is an important first step.

Title: Re: The integer Mandelbrot bench
Post by: JRS on May 06, 2014, 02:13:46 PM
Ed,

Can you add this C BASIC 64 bit version of your benchmark to your list?

Code: [Select]
#include <stdio.h>
#include "cbasic.h"

MAIN
BEGIN_FUNCTION
  DIM AS int left_edge, right_edge, top_edge, bottom_edge, max_iter,
             x_step, y_step, y0, x0, x, y, i, x_x, y_y, temp,
             the_char, accum, count;
  accum = 0;
  count = 0;
  DEF_WHILE (count < 1545)
  BEGIN_WHILE
    left_edge = -420;
    right_edge = 300;
    top_edge = 300;
    bottom_edge = -300;
    x_step = 7;
    y_step = 15;
    max_iter =  200;
    y0 = top_edge;
    DEF_WHILE (y0 > bottom_edge)
    BEGIN_WHILE
      x0 = left_edge;
      DEF_WHILE (x0 < right_edge)
      BEGIN_WHILE
        y = 0;
        x = 0;
        the_char = 32;
        x_x = 0;
        y_y = 0;
        i = 0;
        DEF_WHILE (i < max_iter AND x_x + y_y <= 800)
        BEGIN_WHILE
          x_x = (x * x) / 200;
          y_y = (y * y) / 200;
          IF (x_x + y_y > 800 ) THEN
            the_char = 48 + i;
            IF  (i > 9) THEN
              the_char = 64;
            END_IF
          ELSE
            temp = x_x - y_y + x0;
            IF ((x < 0 AND y > 0) OR (x > 0 AND y < 0)) THEN
              y = (-1 * ((-1 * (x * y)) / 100)) + y0;
            ELSE
              y = x * y / 100 + y0;
            END_IF
            x = temp;
          END_IF
          i = i + 1;
        WEND
        accum = accum + the_char;
        x0 = x0 + x_step;
      WEND
      y0 = y0 - y_step;
    WEND
    IF (count MOD 300 EQ 0) THEN_DO PRINT ("%d\n", accum);
    count = count + 1;
  WEND
  PRINT ("%d\n", accum);
  RETURN_FUNCTION(0);
END_FUNCTION

jrs@laptop:~/C_BASIC/xlate$ gcc -O3 edbench.c -o edbench
jrs@laptop:~/C_BASIC/xlate$ time ./edbench
200574
60372774
120544974
180717174
240889374
301061574
309886830

real   0m2.028s
user   0m2.024s
sys   0m0.000s
jrs@laptop:~/C_BASIC/xlate$


.
Title: Re: The integer Mandelbrot bench
Post by: Mike Lobanovsky on May 06, 2014, 05:04:52 PM
Hello John,

1. Your code contains two cheats (or typos, if you prefer): :)
-- DEF_WHILE() that's third from the top reads && instead of AND; and
-- bottommost IF reads % instead of MOD.

2. Why bother about GCC -O3 if you can get this for free: :D

.
Title: Re: The integer Mandelbrot bench
Post by: JRS on May 06, 2014, 05:18:27 PM
Good catch. (above code corrected) Dropping the -O3 added more than a second to the time.

jrs@laptop:~/C_BASIC/xlate$ gcc edbench.c -o edbench
jrs@laptop:~/C_BASIC/xlate$ time ./edbench
200574
60372774
120544974
180717174
240889374
301061574
309886830

real   0m3.576s
user   0m3.572s
sys   0m0.000s
jrs@laptop:~/C_BASIC/xlate$
Title: Re: The integer Mandelbrot bench
Post by: Mike Lobanovsky on May 06, 2014, 05:31:25 PM
Dropping the -O3 added more than a second to the time.

Oh John, if only my DynC were doing in its fraction of a millisecond what GCC does in a second, I would be richer than Linus Torvalds (http://www.celebritynetworth.com/richest-businessmen/linus-torvalds-net-worth/) and would be living somewhere at Les Champs-Élysées in Paris.  ;D
Title: Re: The integer Mandelbrot bench
Post by: JRS on May 06, 2014, 07:04:52 PM
I'm impressed. Embedded C BASIC.  :D
Title: Re: The integer Mandelbrot bench
Post by: Mike Lobanovsky on May 06, 2014, 07:31:40 PM
I'm impressed. Embedded C BASIC.  :D

Exactly. You can add yet another slogan to CBASIC's virtues: fully embeddable as-is. :D
Title: Re: The integer Mandelbrot bench
Post by: JRS on May 06, 2014, 10:04:00 PM
Here is C BASIC embedded as an extension module.

Code: [Select]
DECLARE SUB Mandel ALIAS "Int_Mandle_Bench" LIB "imb"

Mandel

Here is the Script BASIC imb.so extension module code.

Code: [Select]
/* The integer Mandelbrot bench

UXLIBS:
DWLIBS:

*/

#include <stdio.h>
#include "../../basext.h"

/**************************
 Extension Module Functions
**************************/

besVERSION_NEGOTIATE
  RETURN_FUNCTION((int)INTERFACE_VERSION);
besEND

besSUB_START
  DIM AS long *p;
  besMODULEPOINTER = besALLOC(sizeof(long));
  IF (besMODULEPOINTER EQ NULL) THEN_DO RETURN_FUNCTION(0);
  p = (long*)besMODULEPOINTER;
  RETURN_FUNCTION(0);
besEND

besSUB_FINISH
  DIM AS long *p;
  p = (long*)besMODULEPOINTER;
  IF (p EQ NULL) THEN_DO RETURN_FUNCTION(0);
  RETURN_FUNCTION(0);
besEND

besFUNCTION(Int_Mandle_Bench)
  DIM AS int left_edge, right_edge, top_edge, bottom_edge, max_iter,
             x_step, y_step, y0, x0, x, y, i, x_x, y_y, temp,
             the_char, accum, count;
  accum = 0;
  count = 0;
  DEF_WHILE (count < 1545)
  BEGIN_WHILE
    left_edge = -420;
    right_edge = 300;
    top_edge = 300;
    bottom_edge = -300;
    x_step = 7;
    y_step = 15;
    max_iter =  200;
    y0 = top_edge;
    DEF_WHILE (y0 > bottom_edge)
    BEGIN_WHILE
      x0 = left_edge;
      DEF_WHILE (x0 < right_edge)
      BEGIN_WHILE
        y = 0;
        x = 0;
        the_char = 32;
        x_x = 0;
        y_y = 0;
        i = 0;
        DEF_WHILE (i < max_iter AND x_x + y_y <= 800)
        BEGIN_WHILE
          x_x = (x * x) / 200;
          y_y = (y * y) / 200;
          IF (x_x + y_y > 800 ) THEN
            the_char = 48 + i;
            IF  (i > 9) THEN
              the_char = 64;
            END_IF
          ELSE
            temp = x_x - y_y + x0;
            IF ((x < 0 AND y > 0) OR (x > 0 AND y < 0)) THEN
              y = (-1 * ((-1 * (x * y)) / 100)) + y0;
            ELSE
              y = x * y / 100 + y0;
            END_IF
            x = temp;
          END_IF
          i = i + 1;
        WEND
        accum = accum + the_char;
        x0 = x0 + x_step;
      WEND
      y0 = y0 - y_step;
    WEND
    IF (count MOD 300 EQ 0) THEN_DO PRINT ("%d\n", accum);
    count = count + 1;
  WEND
  PRINT ("%d\n", accum);
  RETURN_FUNCTION(0);
besEND

Results

jrs@laptop:~/sb/sb22/test$ time scriba mandel.sb
200574
60372774
120544974
180717174
240889374
301061574
309886830

real    0m2.036s
user    0m2.020s
sys     0m0.004s
jrs@laptop:~/sb/sb22/test$

@Ed - Can you update the time for Script BASIC. (scriba)   ;D
Title: Re: The integer Mandelbrot bench
Post by: JRS on May 06, 2014, 11:57:16 PM
This time I'm embedding the Script BASIC API in C BASIC which is running the same script above which calls the C BASIC extension module that contains the Integer Mandel Benchmark.

sbembed.c
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "scriba.h"
#include "cbasic.h"

MAIN
BEGIN_FUNCTION
  DIM AS pSbProgram pProgram;
  pProgram = scriba_new(malloc,free);
  scriba_LoadConfiguration(pProgram, "/home/jrs/sb/sb22/bin/basic.conf");
  scriba_SetFileName(pProgram, argv[1]);
  scriba_LoadSourceProgram(pProgram);
  scriba_Run(pProgram, argv[2]);
  scriba_destroy(pProgram);
  RETURN_FUNCTION(0);
END_FUNCTION


jrs@laptop:~/sb/sb22/test$ time ./sbembed mandel.sb
200574
60372774
120544974
180717174
240889374
301061574
309886830

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

Title: Re: The integer Mandelbrot bench
Post by: Mike Lobanovsky on May 07, 2014, 03:56:37 AM
LOL John,

I'm lazying today but if I weren't, I would:

1. Write and execute an FBSL script that would:
-- load the Mandel script and C BASIC header files separately;
-- open a sender socket;
-- spawn another FBSL process that would open a receiver socket;
-- send to the other FBSL process over the sockets the Mandel script, C BASIC header, 1545 as the Mandel iteration limit, and yet another script that would force that other process ...

2. ... to perform the following:
-- concatenate the Mandel script with the C BASIC header;
-- load Fbsl.dll and pass to it the merged script, 1545 as the Mandel iteration limit, and yet another script that would force Fbsl.dll ...

3. ... to perform the following:
-- accept the merged script and wrap it into a DynC function;
-- pass 1545 as the DynC function argument;
-- run the Mandel benchmark to its upper limit of 1545 iterations in the DynC function in its own Dynamic C layer;
-- stopwatch the execution time and display the benchmark results.

All that without using any extra modules whatsoever.

Obviously, scripts and/or executables written in any other suitable language might be used at stages 1 and 2.
Title: Re: The integer Mandelbrot bench
Post by: JRS on May 07, 2014, 07:35:34 AM
Glad you're being lazy today!   8)
Title: Re: The integer Mandelbrot bench
Post by: JRS on May 29, 2014, 02:53:56 PM
I have been working with Android native Linux recently and thought I would run Ed's integer Mandelbrot benchmark on my Galaxy Tab 2 using C BASIC

(http://files.allbasic.info/C_BASIC/imandel_cb_android.png)

Here is the same C BASIC program but running 64 bit on my Laptop.

jrs@laptop:~/C_BASIC/xlate$ time ./imandel
200574
60372774
120544974
180717174
240889374
301061574
309886830

real   0m2.028s
user   0m2.020s
sys   0m0.004s
jrs@laptop:~/C_BASIC/xlate$

Code: [Select]
#include <stdio.h>
#include "cbasic.h"

MAIN
BEGIN_FUNCTION
  DIM AS int left_edge, right_edge, top_edge, bottom_edge, max_iter,
             x_step, y_step, y0, x0, x, y, i, x_x, y_y, temp,
             the_char, accum, count;
  accum = 0;
  count = 0;
  DEF_WHILE (count < 1545)
  BEGIN_WHILE
    left_edge = -420;
    right_edge = 300;
    top_edge = 300;
    bottom_edge = -300;
    x_step = 7;
    y_step = 15;
    max_iter =  200;
    y0 = top_edge;
    DEF_WHILE (y0 > bottom_edge)
    BEGIN_WHILE
      x0 = left_edge;
      DEF_WHILE (x0 < right_edge)
      BEGIN_WHILE
        y = 0;
        x = 0;
        the_char = 32;
        x_x = 0;
        y_y = 0;
        i = 0;
        DEF_WHILE (i < max_iter AND x_x + y_y <= 800)
        BEGIN_WHILE
          x_x = (x * x) / 200;
          y_y = (y * y) / 200;
          IF (x_x + y_y > 800 ) THEN
            the_char = 48 + i;
            IF  (i > 9) THEN
              the_char = 64;
            END_IF
          ELSE
            temp = x_x - y_y + x0;
            IF ((x < 0 AND y > 0) OR (x > 0 AND y < 0)) THEN
              y = (-1 * ((-1 * (x * y)) / 100)) + y0;
            ELSE
              y = x * y / 100 + y0;
            END_IF
            x = temp;
          END_IF
          i = i + 1;
        WEND
        accum = accum + the_char;
        x0 = x0 + x_step;
      WEND
      y0 = y0 - y_step;
    WEND
    IF (count MOD 300 EQ 0) THEN_DO PRINT ("%d\n", accum);
    count = count + 1;
  WEND
  PRINT ("%d\n", accum);
  RETURN_FUNCTION(0);
END_FUNCTION

@Ed - You have Scriba (Script BASIC) noted as Pure (direct  text to execution) when in fact SB compiles/tokenized/PCode and syntax checks the program before execution starts. Scripts can be cached in their binary form for faster execution and load time.
Title: Re: The integer Mandelbrot bench
Post by: JRS on June 04, 2014, 05:03:45 PM
I was able to break the 2 second barrier running Ed's integer Mandelbrot on Koding.com. (FREE account (https://koding.com/R/johnspikowski) )

Quote
What is Koding?

Koding is an online development environment with the goal of simplifying worldwide development and providing free computation and development to everyone. It does this by offering Free VMs for development to anyone. The Koding VMs provide you with a real Ubuntu OS, with areal Terminal, and allow you to work on real code. Python,PHP, C++, C, it doesn’t matter. Even better, they are online. Accessible from anywhere in the world. Even sharable with teams.

FYI: I canceled my Cloud9 IDE account.

(http://files.allbasic.info/Koding/imandel_koding.png)


(http://files.allbasic.info/Koding/koding_free.png)
Title: Re: The integer Mandelbrot bench
Post by: JRS on May 11, 2015, 11:16:03 AM
Hi Ed,

Thanks for the PM with a copy of your benchmark for SB. Sorry to say it runs forever. (assumed - I gave up after 13 minutes) Maybe it's a 64 bit issue or something else. I will give it a try on my XP VirtualBox and see it runs there.

Code: Script BASIC
  1. accum = 0
  2. count = 0
  3. while count < 1545
  4.     left_edge   = -420
  5.     right_edge  =  300
  6.     top_edge    =  300
  7.     bottom_edge = -300
  8.     x_step      =  7
  9.     y_step      =  15
  10.  
  11.     max_iter    =  200
  12.  
  13.     y0 = top_edge
  14.     while y0 > bottom_edge
  15.         x0 = left_edge
  16.         while x0 < right_edge
  17.             y = 0
  18.             x = 0
  19.             the_char = 32
  20.             x_x = 0
  21.             y_y = 0
  22.             i = 0
  23.             while i < max_iter and x_x + y_y <= 800
  24.                 x_x = (x * x) \ 200
  25.                 y_y = (y * y) \ 200
  26.                 if x_x + y_y > 800 then
  27.                     the_char = 48 + i
  28.                     if i > 9 then
  29.                         the_char = 64
  30.                     end if
  31.                 else
  32.                     temp = x_x - y_y + x0
  33.                     if (x < 0 and y > 0) or (x > 0 and y < 0) then
  34.                         y = (-1 * (-1 * x * y) \ 100) + y0
  35.                     else
  36.                         y = (x * y \ 100) + y0
  37.                     end if
  38.                     x = temp
  39.                 end if
  40.  
  41.                 i = i + 1
  42.             wend
  43.             accum = accum + the_char
  44.  
  45.             x0 = x0 + x_step
  46.         wend
  47.  
  48.         y0 = y0 - y_step
  49.     wend
  50.  
  51.     if count % 300 = 0 then
  52.         print accum, " "
  53.     end if
  54.  
  55.     count = count + 1
  56. wend
  57.  
  58. print accum
  59.  


jrs@laptop:~$ cd sb/sb22/test
jrs@laptop:~/sb/sb22/test$ time scriba edbench.sb
^C

real   13m19.104s
user   13m15.926s
sys   0m0.399s
jrs@laptop:~/sb/sb22/test$

Title: Re: The integer Mandelbrot bench
Post by: Ed Davis on May 11, 2015, 11:42:51 AM
Hi Ed,

Thanks for the PM with a copy of your benchmark for SB. Sorry to say it runs forever. (assumed - I gave up after 13 minutes) Maybe it's a 64 bit issue or something else. I will give it a try on my XP VirtualBox and see it runs there.

Change the main loop counter of 1545 to 15, and see how long that takes.  Multiply that result time by 103, and you'll get an approximate idea of how long it will take to run the full test (e.g., with the loop counter at 1545).


Title: Re: The integer Mandelbrot bench
Post by: JRS on May 11, 2015, 12:18:02 PM
Quote from: Ed Davis
Change the main loop counter of 1545 to 15 ...

Thanks Ed!

That would be just over 16 minutes on my laptop.  :'(

jrs@laptop:~/sb/sb22/test$ time scriba edbench.sb
200574 3008610
real   0m9.494s
user   0m9.442s
sys   0m0.028s
jrs@laptop:~/sb/sb22/test$

As a test to see if SB WHILE is a pig, I converted your benchmark to use IF/GOTO for the looping structure. No improvement I'm afraid.

Code: Script BASIC
  1. accum = 0
  2. count = 0
  3. W0:
  4. IF count < 15 THEN
  5. ' while count < 15
  6.    left_edge   = -420
  7.     right_edge  =  300
  8.     top_edge    =  300
  9.     bottom_edge = -300
  10.     x_step      =  7
  11.     y_step      =  15
  12.  
  13.     max_iter    =  200
  14.  
  15.     y0 = top_edge
  16. W1:
  17.     IF y0 > bottom_edge THEN
  18. '   while y0 > bottom_edge
  19.        x0 = left_edge
  20. W2:
  21.         IF x0 < right_edge THEN
  22. '       while x0 < right_edge
  23.            y = 0
  24.             x = 0
  25.             the_char = 32
  26.             x_x = 0
  27.             y_y = 0
  28.             i = 0
  29. W3:
  30.             IF i < max_iter and x_x + y_y <= 800 THEN
  31. '           while i < max_iter and x_x + y_y <= 800
  32.                x_x = (x * x) \ 200
  33.                 y_y = (y * y) \ 200
  34.                 if x_x + y_y > 800 then
  35.                     the_char = 48 + i
  36.                     if i > 9 then
  37.                         the_char = 64
  38.                     end if
  39.                 else
  40.                     temp = x_x - y_y + x0
  41.                     if (x < 0 and y > 0) or (x > 0 and y < 0) then
  42.                         y = (-1 * (-1 * x * y) \ 100) + y0
  43.                     else
  44.                         y = (x * y \ 100) + y0
  45.                     end if
  46.                     x = temp
  47.                 end if
  48.  
  49.                 i = i + 1
  50. '           wend
  51.            GOTO W3
  52.             END IF
  53.             accum = accum + the_char
  54.  
  55.             x0 = x0 + x_step
  56. '       wend
  57.        GOTO W2
  58.         END IF
  59.  
  60.         y0 = y0 - y_step
  61. '   wend
  62.    GOTO W1
  63.     END IF
  64.  
  65.     if count % 300 = 0 then
  66.         print accum, " "
  67.     end if
  68.  
  69.     count = count + 1
  70. ' wend
  71. GOTO W0
  72. END IF
  73. print accum
  74.  


jrs@laptop:~/sb/sb22/test$ time scriba edbench4.sb
200574 3008610
real   0m9.680s
user   0m9.662s
sys   0m0.000s
jrs@laptop:~/sb/sb22/test$