Jump to content

How high can you compute pi?

Nallown

Hey guys I just created this Java code which computes pi up to unlimited digits and I thought, lets put this to the test and find it's limit.

So basically the idea is to see how high your computer can compute pi, I tried keeping the source as light weight as possible and since I created it on a old crappy laptop while I was on the train this should mean that anyone can run it with no issues.

 

So here's the source and have fun with it :)

import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.io.PrintWriter;import java.math.BigInteger; public class ComputePi {	final static BigInteger two = BigInteger.valueOf(2);	final static BigInteger three = BigInteger.valueOf(3);	final static BigInteger four = BigInteger.valueOf(4);	final static BigInteger seven = BigInteger.valueOf(7); 	static BigInteger q = BigInteger.ONE;	static BigInteger r = BigInteger.ZERO;	static BigInteger t = BigInteger.ONE;	static BigInteger k = BigInteger.ONE;	static BigInteger n = BigInteger.valueOf(3);	static BigInteger l = BigInteger.valueOf(3);	static PrintWriter out; 	public static void main(String[] args) {		BigInteger nn, nr;		boolean first = true;		int decimals = 0;				try {			out = new PrintWriter(System.getProperty("user.home")+"/out.pi");						while(true){				if(four.multiply(q).add(r).subtract(t).compareTo(n.multiply(t)) == -1){					out.print(n);					if(first){out.print("."); first = false;}					nr = BigInteger.TEN.multiply(r.subtract(n.multiply(t)));					n = BigInteger.TEN.multiply(three.multiply(q).add(r)).divide(t).subtract(BigInteger.TEN.multiply(n));					q = q.multiply(BigInteger.TEN);					r = nr;					out.flush();					decimals++;					System.out.println((decimals-1)+", Decimals Computed");				}else{					nr = two.multiply(q).add(r).multiply(l);					nn = q.multiply((seven.multiply(k))).add(two).add(r.multiply(l)).divide(t.multiply(l));					q = q.multiply(k);					t = t.multiply(l);					l = l.add(two);					k = k.add(BigInteger.ONE);					n = nn;					r = nr;				}			}		}catch (IOException e) {			e.printStackTrace();		}finally{			out.close();		}	}	} 

The final results of pi computed is outputted in your user folder (c:\users\your user), people running linux would know where their final outputted file would be found.

Keep in mind that the console mentions how many decimal places it has found but the final outputted file has all digits from 3.1 to the final computed digit.

 

file is called output.pi and also the results found inside of it are computed in realtime. So in theory you can use watch in linux to watch it change in realtime and also if your computer crashes then the final results should show your pc's limits since before continuing on to the next digit it would output it into the file.

 

Don't forget to post your final results and how long you've been running it for ;)

 

Keep in mind that this isn't the most efficient way of computing pi, if you want to break the world record and get something in the million digits then you're better of using a assembly based pi calculator since that would directly communicate with the hardware in a way so it would only request the required data unlike java which would run tasks in the background to execute a function. 

 

Edit: Added instructions and java file for people who don't know how to program 

 
 

!Important read if you don't know how to program or got no programming experience!

 

To run follow these steps otherwise it'll be running invisibly in the background which is no issue because it only uses 8mb ram but still

  1. Download this file
  2. Shift right click the folder (or desktop) where you saved the file
  3. Choose " Open command window here "
  4. type in " java -jar computePi.jar "
  5. And go!!!!

If you accidentally double click it then just force close java through task manager when you want to close it or otherwise if you run it with my instructions then simply close the command window

Edited by Nallown
Link to comment
Share on other sites

Link to post
Share on other sites

I am total programming noob. How do I use? :P

 

what program do i use to run it?

 

 

i'll run it overnight tonight if you reply with how to, until around 6PM tomorrow.

 

Ok in that case I will compile it and upload it gimme a sec

Link to comment
Share on other sites

Link to post
Share on other sites

I am a programmer and never did java just so I also don't know how to open it :P

Link to comment
Share on other sites

Link to post
Share on other sites

use eclipse to open this program!

current rig (march 2023)

case: Corsair obsidian 750D   mobo: Gigabyte X470 Aorus Ultra Gaming   cpu: AMD Ryzen 7 5800x   cooler: Arctic Liquid Freezer II 240   memory: G.skill 32GB DDR4-3000   gpu: EVGA RTX 3070 XC3  PSU: seasonic X-series 850W

 

Link to comment
Share on other sites

Link to post
Share on other sites

20,000 decimals and counting ... 

38,000+ in 4 minutes

51,000+ in 8-9 minutes

 

This will probably take a while. Running on my laptop with Arch Linux (i5 3320M, 12GB of RAM, 120GB SSD). CPU usage at 34%. 

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Much love  :wub:

cheers brochacho

 

https://mega.co.nz/#!h58DxS5A!9xm1WKe_v0XSdAJUm1zhE0jfKrUrtiYBKU8hDsoXEj0

 

Important read if you don't know how to program or got no programming experience!

To run follow these steps otherwise it'll be running invisibly in the background which is no issue because it only uses 8mb ram but still

  1. Shift right click the folder (or desktop) where you saved the jar
  2. Choose " Open command window here "
  3. type in " java -jar computePi.jar "
  4. And go!!!!

If you accidentally double click it then just force close java through task manager when you want to close it or otherwise if you run it with my instructions then simply close the command window

Link to comment
Share on other sites

Link to post
Share on other sites

https://mega.co.nz/#!Vs8VzDzZ!qSWUM8UWSqh876SDFxzuRpfrgiFxi1TR7lEtaTkuy5w

 

Important read if you don't know how to program or got no programming experience!

To run follow these steps otherwise it'll be running invisibly in the background which is no issue because it only uses 8mb ram but still

  1. Shift right click the folder (or desktop) where you saved the jar
  2. Choose " Open command window here "
  3. type in " java -jar computePi.jar "
  4. And go!!!!

If you occidentally double click it then just force close java through task manager when you want to close it or otherwise if you run it with my instructions then simply close the command window

HOLY MOTHER OF GOD ITS WORKING LIKE CRAZY

Link to comment
Share on other sites

Link to post
Share on other sites

https://mega.co.nz/#!Vs8VzDzZ!qSWUM8UWSqh876SDFxzuRpfrgiFxi1TR7lEtaTkuy5w

 

Important read if you don't know how to program or got no programming experience!

To run follow these steps otherwise it'll be running invisibly in the background which is no issue because it only uses 8mb ram but still

  1. Shift right click the folder (or desktop) where you saved the jar
  2. Choose " Open command window here "
  3. type in " java -jar computePi.jar "
  4. And go!!!!

If you accidentally double click it then just force close java through task manager when you want to close it or otherwise if you run it with my instructions then simply close the command window

thanks lol i leave it running for a while

btw its like 270MB of my ram which really isnt lightweit xD

but now it keeps going smaller and smaller.... wtf

Link to comment
Share on other sites

Link to post
Share on other sites

thanks lol i leave it running for a while

btw its like 270MB of my ram which really isnt lightweit xD

but now it keeps going smaller and smaller.... wtf

If you run it with cmd then it'll use around 150mb ram but if you just run it directly by opening it and let it go in background then it won't worry about outputting how many lines it has so it'll use around 10mb ram and also java uses a percentage of ram available so since you have more ram then I do on my laptop you'd use more

Link to comment
Share on other sites

Link to post
Share on other sites

my work computer doesnt have java installed LMAO

nice one ;) When I get home I might create a c# version which would use the exact same method to compute pi but this is maybe if I can be bother to do so.

Link to comment
Share on other sites

Link to post
Share on other sites

nice one ;) When I get home I might create a c# version which would use the exact same method to compute pi but this is maybe if I can be bother to do so.

i just installed java maybe i need to restart for cmd to recognise java as a command? currently doesn't recognise it as one.

Link to comment
Share on other sites

Link to post
Share on other sites

i just installed java maybe i need to restart for cmd to recognise java as a command? currently doesn't recognise it as one.

You need to add the location of the java executable to the PATH variable. 

http://www.java.com/en/download/help/path.xml

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

i just installed java maybe i need to restart for cmd to recognise java as a command? currently doesn't recognise it as one.

A C# version could just be saved and shared as an .exe file :P

Link to comment
Share on other sites

Link to post
Share on other sites

A C# version could just be saved and shared as an .exe file :P

 

You can bundle jar files as windows executables, the minecraft launcher uses this feature.

 

Additionally.. running it under linux, lets see how it performs on my rig.

Arch Linux on Samsung 840 EVO 120GB: Startup finished in 1.334s (kernel) + 224ms (userspace) = 1.559s | U mad windoze..?

Link to comment
Share on other sites

Link to post
Share on other sites

i just installed java maybe i need to restart for cmd to recognise java as a command? currently doesn't recognise it as one.

if you got windows 7 then in start menu search for "edit system environment variables"

click on "environment variables"

find "path" under 'system variables'

search for your 'java' folder under the 'program files folder' and find the 'jdk' folder inside the java folder and find the 'bin' folder inside the jdk folder

copy the path of the bin folder

click 'edit' in system variables on path

paste the bin folder path in front of everything and add a semi colon ( ; ) after the path [make sure that there are no spaces at all in the line]

Link to comment
Share on other sites

Link to post
Share on other sites

You can bundle jar files as windows executables, the minecraft launcher uses this feature.

 

Additionally.. running it under linux, lets see how it performs on my rig.

would do so but really not worth it for such a small app

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes 30 seconds

33371, 

 

edit: bah I have to go out, 5 minutes 42k~

Just a reminder as the numbers get larger the longer the calculations take, after only a second mine is at 4k, but it takes 2.5minutes to get to 33k

Arch Linux on Samsung 840 EVO 120GB: Startup finished in 1.334s (kernel) + 224ms (userspace) = 1.559s | U mad windoze..?

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes 30 seconds

33371, will update at the 10 minute mark. 

on my crappy laptop I got around 20k at that time mark, once I get home I'll try this for real on my desktop pc

Link to comment
Share on other sites

Link to post
Share on other sites

20,000 decimals and counting ... 

38,000+ in 4 minutes

51,000+ in 8-9 minutes

 

This will probably take a while. Running on my laptop with Arch Linux (i5 3320M, 12GB of RAM, 120GB SSD). CPU usage at 34%. 

Stopped it at around 100k, about 30 minutes. 

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Stopped it at around 100k, about 30 minutes. 

Main reason for it slowing down over time is because the file size of output.pi increases over time it means that it takes longer to read the file holding the previous computed pi and add the next digit to it. Imagine this, reading a sentence is quicker to do so then reading a paragraph and since it needs to read over again to add the next character it would slow down over time.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×