Created
December 24, 2012 11:37
-
-
Save anonymous/4368921 to your computer and use it in GitHub Desktop.
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
Test Setup | |
---------- | |
CPU: 2.2 GHz Intel Core i7 | |
RAM: 16 GB 1333 MHz DDR 3 | |
Disk: OCZ Vertex 4 128G | |
Java: Java SE 1.6 (MacOS X Default) | |
VM Arguments: -Xmx4096m | |
IDE: Eclipse 4.2.1 (M20120914-1800) | |
Tests: JUnit 4 | |
Test Aim | |
-------- | |
This test is assessing the performance hit on using double brace | |
Test Conclusions | |
---------------- | |
Source output | |
------------- | |
Test Runs | |
--------- | |
1. TEST_COUNT = 1,000 | |
testExternalSimpleObjectInitiation 1763281041 | |
Time taken: 14ms | |
testInternalSimpleObjectInitiation 10969598 | |
Time taken: 14ms | |
testTripleExternalSimpleObjectInitiation 1412485250 | |
Time taken: 30ms | |
testTripleInternalSimpleObjectInitiation 906199566 | |
Time taken: 16ms | |
testExternalSimpleListInitiation 1062730578 | |
Time taken: 10ms | |
testInternalSimpleListInitiation 1709834834 | |
Time taken: 8ms | |
2. TEST_COUNT = 10,000 | |
testExternalSimpleObjectInitiation 1891275584 | |
Time taken: 83ms | |
testInternalSimpleObjectInitiation 1133736492 | |
Time taken: 18ms | |
testTripleExternalSimpleObjectInitiation 1336225759 | |
Time taken: 28ms | |
testTripleInternalSimpleObjectInitiation 1709834834 | |
Time taken: 31ms | |
testExternalSimpleListInitiation 1857040122 | |
Time taken: 28ms | |
testInternalSimpleListInitiation 302785728 | |
Time taken: 11ms | |
3. TEST_COUNT = 100,000 | |
testExternalSimpleObjectInitiation 1891275584 | |
Time taken: 179ms | |
testInternalSimpleObjectInitiation 911767762 | |
Time taken: 64ms | |
testTripleExternalSimpleObjectInitiation 301671635 | |
Time taken: 202ms | |
testTripleInternalSimpleObjectInitiation 322714437 | |
Time taken: 233ms | |
testExternalSimpleListInitiation 1793061098 | |
Time taken: 174ms | |
testInternalSimpleListInitiation 456335625 | |
Time taken: 132ms | |
4. TEST_COUNT = 1,000,000 | |
testExternalSimpleObjectInitiation 1763281041 | |
Time taken: 917ms | |
testInternalSimpleObjectInitiation 950233939 | |
Time taken: 753ms | |
testTripleExternalSimpleObjectInitiation 1450554350 | |
Time taken: 2043ms | |
testTripleInternalSimpleObjectInitiation 21845470 | |
Time taken: 2232ms | |
testExternalSimpleListInitiation 876433694 | |
Time taken: 1338ms | |
testInternalSimpleListInitiation 1506092990 | |
Time taken: 2164ms | |
5. TEST_COUNT = 10,000,000 | |
testExternalSimpleObjectInitiation 1763281041 | |
Time taken: 7662ms | |
testInternalSimpleObjectInitiation 911435008 | |
Time taken: 7478ms | |
testTripleExternalSimpleObjectInitiation 851272462 | |
Time taken: 18295ms | |
testTripleInternalSimpleObjectInitiation 1763538368 | |
Time taken: 27457ms | |
testExternalSimpleListInitiation 1180697045 | |
Time taken: 15792ms | |
testInternalSimpleListInitiation 747136299 | |
Time taken: 15549ms |
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.util.ArrayList; | |
import java.util.Calendar; | |
import java.util.List; | |
import java.util.Random; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class SimpleInitiationTest { | |
private static final int TEST_COUNT = 1000000; | |
private Random random = new Random(); | |
private long start; | |
@Before | |
public void setup() { | |
start = Calendar.getInstance().getTimeInMillis(); | |
} | |
@After | |
public void tearUp() { | |
long end = Calendar.getInstance().getTimeInMillis(); | |
System.out.println("Time taken: " + (end - start) + "ms"); | |
} | |
@Test public void testExternalSimpleObjectInitiation() { | |
System.out.println("testExternalSimpleObjectInitiation " + this.hashCode()); | |
List<SimpleObject> results = new ArrayList<SimpleObject>(TEST_COUNT); | |
for (int i = 0; i < TEST_COUNT; i++) { | |
SimpleObject victim = new SimpleObject(); | |
victim.setPage(random.nextInt()); | |
victim.setPageSize(random.nextInt()); | |
victim.setSomeData(Double.toString(random.nextDouble())); | |
results.add(victim); | |
} | |
} | |
@Test public void testInternalSimpleObjectInitiation() { | |
System.out.println("testInternalSimpleObjectInitiation " + this.hashCode()); | |
List<SimpleObject> results = new ArrayList<SimpleObject>(TEST_COUNT); | |
for (int i = 0; i < TEST_COUNT; i++) { | |
SimpleObject victim = new SimpleObject() { | |
{ | |
page = random.nextInt(); | |
pageSize = random.nextInt(); | |
someData = Double.toString(random.nextDouble()); | |
} | |
}; | |
results.add(victim); | |
} | |
} | |
@Test public void testTripleExternalSimpleObjectInitiation() { | |
System.out.println("testTripleExternalSimpleObjectInitiation " + this.hashCode()); | |
List<SimpleObject> results = new ArrayList<SimpleObject>(TEST_COUNT); | |
for (int i = 0; i < TEST_COUNT; i++) { | |
SimpleObject victim = new SimpleObject(); | |
victim.setPage(random.nextInt()); | |
victim.setPageSize(random.nextInt()); | |
victim.setSomeData(Double.toString(random.nextDouble())); | |
results.add(victim); | |
SimpleObject victim2 = new SimpleObject(); | |
victim.setPage(random.nextInt()); | |
victim.setPageSize(random.nextInt()); | |
victim.setSomeData(Double.toString(random.nextDouble())); | |
results.add(victim2); | |
SimpleObject victim3 = new SimpleObject(); | |
victim.setPage(random.nextInt()); | |
victim.setPageSize(random.nextInt()); | |
victim.setSomeData(Double.toString(random.nextDouble())); | |
results.add(victim3); | |
} | |
} | |
@Test public void testTripleInternalSimpleObjectInitiation() { | |
System.out.println("testTripleInternalSimpleObjectInitiation " + this.hashCode()); | |
List<SimpleObject> results = new ArrayList<SimpleObject>(TEST_COUNT); | |
for (int i = 0; i < TEST_COUNT; i++) { | |
SimpleObject victim = new SimpleObject() { | |
{ | |
page = random.nextInt(); | |
pageSize = random.nextInt(); | |
someData = Double.toString(random.nextDouble()); | |
} | |
}; | |
results.add(victim); | |
SimpleObject victim2 = new SimpleObject() { | |
{ | |
page = random.nextInt(); | |
pageSize = random.nextInt(); | |
someData = Double.toString(random.nextDouble()); | |
} | |
}; | |
results.add(victim2); | |
SimpleObject victim3 = new SimpleObject() { | |
{ | |
page = random.nextInt(); | |
pageSize = random.nextInt(); | |
someData = Double.toString(random.nextDouble()); | |
} | |
}; | |
results.add(victim3); | |
} | |
} | |
@Test public void testExternalSimpleListInitiation() { | |
System.out.println("testExternalSimpleListInitiation " + this.hashCode()); | |
List<SimpleList<String>> results = new ArrayList<SimpleList<String>>(TEST_COUNT); | |
for (int i = 0; i < TEST_COUNT; i++) { | |
SimpleList<String> victim = new SimpleList<String>(); | |
victim.add(Integer.toString(random.nextInt())); | |
victim.add(Integer.toString(random.nextInt())); | |
victim.add(Double.toString(random.nextDouble())); | |
results.add(victim); | |
} | |
} | |
@Test public void testInternalSimpleListInitiation() { | |
System.out.println("testInternalSimpleListInitiation " + this.hashCode()); | |
List<SimpleList<String>> results = new ArrayList<SimpleList<String>>(TEST_COUNT); | |
for (int i = 0; i < TEST_COUNT; i++) { | |
SimpleList<String> victim = new SimpleList<String>() { | |
private static final long serialVersionUID = 1L; | |
{ | |
add(Integer.toString(random.nextInt())); | |
add(Integer.toString(random.nextInt())); | |
add(Double.toString(random.nextDouble())); | |
} | |
}; | |
results.add(victim); | |
} | |
} | |
} |
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.util.ArrayList; | |
public class SimpleList<T> extends ArrayList<T> { | |
private static final long serialVersionUID = 1L; | |
} |
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
public class SimpleObject { | |
protected int page; | |
protected int pageSize; | |
protected String someData; | |
public int getPage() { | |
return page; | |
} | |
public void setPage(int page) { | |
this.page = page; | |
} | |
public int getPageSize() { | |
return pageSize; | |
} | |
public void setPageSize(int pageSize) { | |
this.pageSize = pageSize; | |
} | |
public String getSomeData() { | |
return someData; | |
} | |
public void setSomeData(String someData) { | |
this.someData = someData; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment