Created
January 24, 2012 01:41
-
-
Save 19h/1667195 to your computer and use it in GitHub Desktop.
BigInFact Æsthetics Codename Edna
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.BigInteger; | |
import java.text.NumberFormat; | |
/** | |
* | |
* @author Kenan Sulayman | |
* @version Æsthetics Codename Edna | |
*/ | |
/* | |
Loving and living and fighting and falling – flying. | |
Growing and playing and praying and pushing - rising. | |
* But I still love life as I'm flying through the air | |
* When I'm playing, never stuck here | |
* So I still got to push and rise | |
* Even if it's only for a couple more nights | |
* Fighting through the bass like the song's my wife | |
* Give them an idea how we do this like | |
*/ | |
public class BigIntFact { | |
public static Runtime rt; | |
public static BigInteger fa(BigInteger n) { | |
BigInteger ret = new BigInteger("1"); | |
for (BigInteger i = new BigInteger("1"); i.compareTo(n) == -1; i = i.add(new BigInteger("1"))) | |
ret = ret.multiply(i); | |
return ret; | |
} | |
public static void main(String[] args) { | |
rt = rt.getRuntime(); | |
NumberFormat ff = NumberFormat.getInstance(); | |
StringBuilder sb = new StringBuilder(); | |
long f = rt.freeMemory(); | |
long a = f / 1024; | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.out.println("Initializing.. o:"+ff.format(a) + "mb."); | |
sb.append(ff.format(a) + "mb."); // Initial | |
for (int i = 1; i <= 400; ++i) { | |
//memory = mf(); | |
//System.out.println("Iteration " + i + ":"); | |
//System.out.println("\tCurrently used: " + memory + "kb."); | |
//t = System.currentTimeMillis(); | |
fa(new BigInteger(i + "")); // Carry the semi-string into the BigInteger-Class (Auto-Cast!) | |
//System.out.println("\tThe calculation took " + (System.currentTimeMillis() - t) + "ms."); | |
//memory = Math.abs(memory - mf()); | |
//System.out.println("There was an overhead of " + Math.abs(memory - mf()) + "kb. (" + (Math.abs(memory - mf()) / 1048576) + "mb)"); | |
} | |
ff = NumberFormat.getInstance(); | |
sb = new StringBuilder(); | |
long b = rt.freeMemory() / (2 << 9); //1024 | |
a -= (b); // Diff @ a => this::26::26-32 | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
sb.append(ff.format(a)); | |
System.out.print("Quicktest.. ∆ " + sb.toString() + "mb. (" + ff.format(b) + "mb offset-total)\n"); | |
System.out.println("Initializing Hugetest.. <must be all-equal from this point> ! "); | |
// Bytecode: Allocate memory upon reallocation of control-instances; | |
// Redeclaration does actually not reallocate anything. | |
// TRY IMPLEMENTING AS RECURSIVE; | |
// FOR PROPER CALCULATION | |
// USE UNIQUE VARIABLE | |
// WITH AT LEAST 1 SECOND | |
// LATENCY AFTER LAST CALL! | |
for (int i = 10; i <= 400; i+=100){ // FAILS. | |
rt = rt.getRuntime(); | |
ff = NumberFormat.getInstance(); | |
sb = new StringBuilder(); | |
f = rt.freeMemory(); | |
a = f / 1024; | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.out.print("i:"+i+" o:"+ff.format(a) + "mb."); | |
sb.append(ff.format(a) + "mb."); // Initial | |
fa(new BigInteger(i + "")); | |
ff = NumberFormat.getInstance(); | |
sb = new StringBuilder(); | |
b = rt.freeMemory() / (2 << 9); //1024 | |
a -= (b); // Diff @ a => this::26::26-32 | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
System.gc(); System.gc(); System.gc(); System.gc(); | |
sb.append(ff.format(a)); | |
System.out.print(" Ommited <" + sb.toString() + ">mb. (" + ff.format(b) + "mb offset-total)\n"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment