Created
January 2, 2015 05:21
-
-
Save disktnk/813bb0781c35fb4f5ce2 to your computer and use it in GitHub Desktop.
This file contains 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
package objectsize; | |
import java.util.ArrayList; | |
import java.util.List; | |
import net.sourceforge.sizeof.SizeOf; | |
import org.junit.Test; | |
import org.openjdk.jol.info.GraphLayout; | |
import com.twitter.common.objectsize.ObjectSizeCalculator; | |
public class ObjectSizeTest { | |
@Test | |
public void test() { | |
String s = ""; | |
String s2 = "0123456789"; | |
List<String> list = new ArrayList<>(); | |
list.add(s); | |
list.add(s2); | |
{ | |
SizeOf.skipFinalField(false); | |
SizeOf.skipStaticField(true); | |
SizeOf.setMinSizeToLog(40); | |
long sSize = SizeOf.deepSizeOf(s); | |
long s2Size = SizeOf.deepSizeOf(s2); | |
long listSize = SizeOf.deepSizeOf(list); | |
System.out.println("[sizeOf]empty string: " + sSize); | |
System.out.println("[sizeOf]string : " + s2Size); | |
System.out.println("[sizeOf]string list : " + listSize); | |
} | |
{ | |
long sSize = ObjectSizeCalculator.getObjectSize(s); | |
long s2Size = ObjectSizeCalculator.getObjectSize(s2); | |
long listSize = ObjectSizeCalculator.getObjectSize(list); | |
System.out.println("[tc]empty string: " + sSize); | |
System.out.println("[tc]string : " + s2Size); | |
System.out.println("[tc]string list : " + listSize); | |
} | |
{ | |
long sSize = GraphLayout.parseInstance(s).totalSize(); | |
long s2Size = GraphLayout.parseInstance(s2).totalSize(); | |
long listSize = GraphLayout.parseInstance(list).totalSize(); | |
System.out.println("[jol]empty string: " + sSize); | |
System.out.println("[jol]string : " + s2Size); | |
System.out.println("[jol]string list : " + listSize); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment