Created
July 25, 2012 11:24
-
-
Save Zepheus/3175627 to your computer and use it in GitHub Desktop.
javanx benchmark - version 1
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
/* Tests based on a Intel® Core™2 Duo Processor P8700 (3M Cache, 2.53 GHz, 1066 MHz FSB) | |
Loading file & string table took 63ms. | |
Access took 547ms based on 10 results. | |
Full recursion took 2821ms based on 10 results. | |
Memory usage after testing: 899MB*/ | |
package net.zepheus.nxjava.tests; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import net.zepheus.nxjava.NXFile; | |
import net.zepheus.nxjava.NXNode; | |
public class Benchmark { | |
private static final int COUNT = 10; | |
public static void main(String[] args) { | |
try { | |
NXFile file = loadTest("D:\\Games\\MapleBeta\\DataOnly.nx"); | |
accessTest(file, 1000000); | |
recurseTest(file); | |
memoryTest(); | |
file.close(); | |
} catch (Exception ex) { | |
System.out.println(ex.getMessage()); | |
} | |
} | |
private static NXFile loadTest(String path) throws FileNotFoundException, IOException { | |
long start = System.currentTimeMillis(); | |
NXFile file = new NXFile(path); | |
long time = System.currentTimeMillis() - start; | |
System.out.println("Loading file & string table took " + time + "ms."); | |
return file; | |
} | |
private static void memoryTest() | |
{ | |
System.gc(); | |
long usage = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); | |
long MB = usage / (1024 * 1024); | |
System.out.println("Memory usage after testing: " + MB + "MB"); | |
} | |
private static void accessTest(NXFile file, int times) { | |
System.gc(); | |
long start = System.currentTimeMillis(); | |
for(int i = 0; i < times * COUNT; i++) | |
{ | |
NXNode node = file.resolvePath("Effect/BasicEff.img/LevelUp/5/origin"); | |
} | |
long time = System.currentTimeMillis() - start; | |
long average = time / COUNT; | |
System.out.println("Access took " + average +"ms based on " + COUNT + " results."); | |
} | |
private static void recurseTest(NXFile file) { | |
System.gc(); | |
long start = System.currentTimeMillis(); | |
for(int i = 0; i < COUNT; i++) | |
{ | |
recurse(file.getRoot()); | |
} | |
long time = System.currentTimeMillis() - start; | |
long average = time / COUNT; | |
System.out.println("Full recursion took " + average +"ms based on " + COUNT + " results."); | |
} | |
private static void recurse(NXNode node) { | |
for(NXNode child : node) | |
recurse(child); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment