Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here is a BooBoo version #120

Open
ghost opened this issue Oct 18, 2023 · 4 comments
Open

Here is a BooBoo version #120

ghost opened this issue Oct 18, 2023 · 4 comments

Comments

@ghost
Copy link

ghost commented Oct 18, 2023

number rounds
= rounds 100000000
* rounds 2
+ rounds 3

number x
= x 1
number pi
= pi 1.0
number a
number b

number i
= i 3
:next_loop
neg x
= a 1
= b i
/ a b
* a x
+ pi a
+ i 2
? i rounds
jl next_loop

* pi 4

print "%\n" pi
@ghost
Copy link
Author

ghost commented Nov 4, 2023

Here is a BooBoo version with some improvements that reads the number of rounds from a file.

number f
file_open f "rounds.txt" "r"
string s
file_read f s
file_close f
number rounds
= rounds (+ 3 (* s 2))

number x
= x 1
number pi
= pi 1

number i
= i 3
:next_loop
neg x
+ pi (/ x i)
+ i 2
? i rounds
jl next_loop

* pi 4

print "%\n" pi

EDIT: updated it to make it a little bit faster. Perhaps the other benchmarks would benefit.

The only issue now is text formatting, it simply uses %g so it doesn't print all the digits it calculated.

@ghost
Copy link
Author

ghost commented Nov 5, 2023

I've added formatting options so it's fully functional.

number f
file_open f "rounds.txt" "r"
string s
file_read f s
file_close f
number rounds
= rounds (+ 3 (* s 2))

number x
= x 1
number pi
= pi 1

number i
= i 3
:next_loop
neg x
+ pi (/ x i)
+ i 2
? i rounds
jl next_loop

* pi 4

print "%(3.16g)\n" pi

@ghost
Copy link
Author

ghost commented Nov 5, 2023

It's a bit slower than Python but faster than ruby or perl for me.

@ghost
Copy link
Author

ghost commented Nov 6, 2023

I added for loops to BooBoo and that cut the overhead significantly, it is now quite a bit faster than Python but still slower than Lua.

number f
file_open f "rounds.txt" "r"
string s
file_read f s
file_close f
number rounds
= rounds (+ 3 (* s 2))

number x
= x 1
number pi
= pi 1
number i
= i 3

for i rounds 2 loop_end
neg x
+ pi (/ x i)
:loop_end

* pi 4

print "%(3.16g)\n" pi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants