Have you ever wondered how fast is a 8-bit CPU (such as 6502 used by famicom and the clones)?
Well, i can’t have a direct comparison for you for now, but for the BASIC programming language (many famicom clones do have this shipped onboard with keyboard), we can have a little experiment.
SB2000, the famicom clone (with keyboard), as described here, will be our testbed. We are going to write a small piece of code, to roughly test the performance, at least have an idea of how fast the 8-bit CPU is (on F-BASIC, floating point BASIC)
Let’s launch the FBASIC from the SB-DOS command line (or you can double click the icon on SB-WIN)
A welcome window (splash) is shown for a couple of seconds:
And finally we arrive at the main window of SB2000 FBASIC.
Look, we have a dropdown menu at the above, which is considered quite advanced at that time. You can select the menu items using the mouse.
And there is an online inbuilt help system (Chinese of course)
Let’s write a small piece of code to compute the approximation of the PI constant using Monte-Carlo simulation random method.
Well, I set the N=10000 in the first place, and I found out it took ages to run, therefore, 100 is reasonable for the time being.
The FBASIC source code is:
1 2 3 4 5 6 7 8 | 10 N=100 20 C=0 30 FOR I=1 TO N 40 X=RND(1000)/1000.0 50 Y=RND(1000)/1000.0 60 IF X*X+Y*Y<=1.0 THEN C=C+1 70 NEXT I 80 PRINT 4.0*C/N |
10 N=100 20 C=0 30 FOR I=1 TO N 40 X=RND(1000)/1000.0 50 Y=RND(1000)/1000.0 60 IF X*X+Y*Y<=1.0 THEN C=C+1 70 NEXT I 80 PRINT 4.0*C/N
For N=100 it even took a couple of seconds! With such small iterations, you can’t really find a good approximation value for
F-BASIC is really really slow, because of 1. it is 8-bit, 2, it is an interpreting language (not assembly).
There is even no such thing date, time available so you can’t really know how to time your program! Also, peek, poke are not available. These functions are used to read and write to memory address, which are considered the useful powerful methods (for instance, you can dump the BIOS in BASIC). Also, the play is not possible. The play will trigger the speaker to play some tones…
One last thing, the maximum length of a string in SB2000-FBASIC is 28. The interpreter will complain and throw a error message during runtime whenever a string exceeds 28 characters.
Monte Carlo Simulation Algorithms to compute the Pi based on Randomness:
- Using Parallel For in Java to Compute PI using Monte Carlo Algorithm
- Monte Carlo solution for Mathematics × Programming Competition #7
- R Programming Tutorial – How to Compute PI using Monte Carlo in R?
- C++ Coding Exercise – Parallel For – Monte Carlo PI Calculation
- Area of the Shadow? – The Monte Carlo Solution in VBScript
- VBScript Coding Exercise – Compute PI using Monte Carlo Random Method
- Computing Approximate Value of PI using Monte Carlo in Python
- How does the 8-bit BASIC perform on Famicom Clone – Subor SB2000 – FBasic – Compute PI approximation using Monte-Carlo method
- GoLang: Compute the Math Pi Value via Monte Carlo Simulation
- BASH Script to Compute the Math.PI constant via Monte Carlo Simulation
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: C/C++ Coding Exercise - Finding Approximation of Pi using Monto-Carlo Algorithm
Next Post: C/C++ Coding Exercise, Valid Parentheses - LeetCode Online Judge - Using Stack