Example usage for jdk.nashorn.internal.ir.debug ObjectSizeCalculator getObjectSize

List of usage examples for jdk.nashorn.internal.ir.debug ObjectSizeCalculator getObjectSize

Introduction

In this page you can find the example usage for jdk.nashorn.internal.ir.debug ObjectSizeCalculator getObjectSize.

Prototype

public static long getObjectSize(final Object obj) throws UnsupportedOperationException 

Source Link

Document

Given an object, returns the total allocated size, in bytes, of the object and all other objects reachable from it.

Usage

From source file:org.bosik.merklesync.TestMemoryMerkleTree.java

License:Apache License

@Test
@Ignore("This test case is for manual performance check only")
public void test_performance_memory() {
    //      MemoryMerkleTree              13 386 880 (bytes)
    //      MemoryMerkleTree2              7 549 880 (bytes)
    //      MemoryMerkleTree3              2 516 720 (bytes)

    String[] arrayString = new String[MAX_MAP.size()];
    for (int i = 0; i < arrayString.length; i++) {
        arrayString[i] = HashUtils.generateGuid();
    }/* ww  w  .j a va2s. c o m*/

    byte[][] arrayByte = new byte[MAX_MAP.size()][16];
    for (byte[] anArrayByte : arrayByte) {
        for (int j = 0; j < 16; j++) {
            new Random().nextBytes(anArrayByte);
        }
    }

    System.out.println("SIZE (byes)");
    System.out.printf("%-25s\t%10d%n", "HashMap", ObjectSizeCalculator.getObjectSize(MAX_MAP));
    System.out.printf("%-25s\t%10d%n", MemoryMerkleTree.class.getSimpleName(),
            ObjectSizeCalculator.getObjectSize(MAX_MERKLE_TREE));
    System.out.printf("%-25s\t%10d%n", MemoryMerkleTree2.class.getSimpleName(),
            ObjectSizeCalculator.getObjectSize(MAX_MERKLE_TREE_2));
    System.out.printf("%-25s\t%10d%n", MemoryMerkleTree3.class.getSimpleName(),
            ObjectSizeCalculator.getObjectSize(MAX_MERKLE_TREE_3));
    System.out.printf("%-25s\t%10d%n", "String array", ObjectSizeCalculator.getObjectSize(arrayString));
    System.out.printf("%-25s\t%10d%n", "Byte array", ObjectSizeCalculator.getObjectSize(arrayByte));
}