RetroBASIC
Basicprogramming(.org) => Code and examples => Topic started by: Galileo on September 05, 2018, 05:26:51 PM
-
I'm back.
Calculation of "some" pi digits.
// Cálculo de pi --- Pi calculation
// Translation from Phix code to Yabasic by Galileo, 09/2018.
n = 35001 : a = 10000 : dim f(n)
for i = 1 to n : f(i) = 2000 : next i
for c = n to 14 step -14
d = 0
for b = c to 1 step -1
d = d * b
g = b * 2 - 1
d = d + f(b) * a
f(b) = mod(d, g)
d = int(d / g)
k = e + int(d / a)
next
k2$ = "000000" + str$(k)
print right$(k2$, 4);
e = mod(d, a)
next
print "\nTime insumed: ", peek("millisrunning") / 1000, " seconds."
In my machine, delayed about 55 secs. Phix code about 21 secs.
-
It looks familiar. I think that the Pix code is a translation of my code. ;)
-
It looks familiar. I think that the Pix code is a translation of my code. ;)
Could you show the code? What dialect did you use? What's the performance?
By the way, the same code in Lua 5.3 takes about 65 seconds (on my machine). I didn't expect it.
-
https://openeuphoria.org/forum/m/132983.wc
Euphoria and Lua.
Pirx == Tomaaz. I had problems with registering on that forum and tried several times. Finally they activated that Pirx account. Luajit less than 1 sec.
-
But LuaJIT doesn't belong in the same league. Or am I wrong?
-
But LuaJIT doesn't belong in the same league.
And why would that be?
-
About the only reason I can think of is that LuaJIT executes compiled code (in the form of a dynarec) as opposed to a bytecode or pure interpreting engine.
-
About the only reason I can think of is that LuaJIT executes compiled code (in the form of a dynarec) as opposed to a bytecode or pure interpreting engine.
Yes, but by accepting this point of view you agree that we can't compare almost anything. BaCon, Pure Basic, NaaLaa, Yabasic, Luajit - they all do things in a different way. You can't even compare 32-bit version of FreeBASIC to it's 64-bit equivalent, cause one translates to C and use C compiler, while the other don't (forgive me, if I'm wrong). And I think it's more interesting to compare different things than to compare similar things.
-
To be honest, I've been thinking about using a Dynarec for SpecBAS. There's only so far a stack-based bytecode implementation will take you for speed concerns. But then, SpecBAS doesn't really need it as nobody is using it for CPU-intensive tasks (and that's not a job for a BASIC in any case, IMO), and as all the heavy lifting is done via my library of support routines, the language itself is just a method for calling that at the end of the day.
To be fair, I suppose if LuaJIT is BASIC-alike enough in its language implementation (and that's a very, very wide field these days - we have strayed so, so far from Dartmouth) then it can indeed be compared to others.
-
Phix-to-Yabasic conversion again. Little faster.
t1 = peek("millisrunning")
chki = 1
a = 10000
c = 35000 // 8400
fr = int(a / 5)
dim f(c)
for i = 1 to c : f(i) = fr : next
while(c > 0)
g = 2 * c
d = 0
b = c
while(b > 0)
d = d + f(b) * a
g = g - 1
f(b) = mod(d, g)
d = int(d / g)
g = g - 1
b = b - 1
if not(b = 0) d = d * b
wend
c = c - 14
n4$ = str$(e + int(d / a),"%04g")
print n4$;
e = mod(d, a)
wend
print "\nTime elapsed: ", (peek("millisrunning") - t1) / 1000, " seconds"