GithubHelp home page GithubHelp logo

sizeof4j's Introduction

sizeof4j

Build Status Coverage Status Maven Central ![License](http://img.shields.io/:license-Apache 2.0-blue.svg)

A Java library for measuring memory size of Java objects.

import com.arturmkrtchyan.sizeof4j.util.ConsoleUtil;

import static java.lang.System.out;

class Main {

    public static void main(String[] args) {

        ConsoleUtil.printJvmDetails();

        out.println("\n\nSizeOf");
        out.println("=================================");

        out.println(" --------------------------");
        out.println("|       Primitives         |");
        out.println(" --------------------------");
        out.println("byte:       " + SizeOf.byteSize());
        out.println("boolean:    " + SizeOf.booleanSize());
        out.println("short:      " + SizeOf.shortSize());
        out.println("char:       " + SizeOf.charSize());
        out.println("int:        " + SizeOf.intSize());
        out.println("float:      " + SizeOf.floatSize());
        out.println("long:       " + SizeOf.longSize());
        out.println("double:     " + SizeOf.doubleSize());

        out.println(" --------------------------");
        out.println("|     Classic Objects      |");
        out.println(" --------------------------");
        out.println("Object:     " + SizeOf.shallowSize(Object.class));
        out.println("Integer:    " + SizeOf.shallowSize(new Integer(2)));
        out.println("String:     " + SizeOf.shallowSize(new String("aaa")));

        out.println(" --------------------------");
        out.println("|      Custom Objects      |");
        out.println(" --------------------------");
        out.println("A:          " + SizeOf.shallowSize(new A()));
        out.println("B:          " + SizeOf.shallowSize(new B()));
        out.println("C:          " + SizeOf.shallowSize(new C()));


        out.println(" --------------------------");
        out.println("|      Class Objects      |");
        out.println(" --------------------------");
        out.println("int.class:  " + SizeOf.shallowSize(int.class));
        out.println("D.class:    " + SizeOf.shallowSize(D.class));

        out.println(" --------------------------");
        out.println("|           Arrays         |");
        out.println(" --------------------------");
        out.println("int[]:      " + SizeOf.shallowSize(new int[]{}));
        out.println("int[2]:     " + SizeOf.shallowSize(new int[]{1, 2}));
        out.println("int[].class " + SizeOf.shallowSize(int[].class));
        out.println("C[].class   " + SizeOf.shallowSize(C[].class));
        out.println("C[2]:       " + SizeOf.shallowSize(new C[]{new C(), new C()}));
    }

    private static class A {
        private int i;
    }

    private static class B {
        private int i;
        private java.util.Locale l = java.util.Locale.US;
    }

    private static class C {
        private int i;
        private java.util.HashMap hm = new java.util.HashMap();
    }

    private static class D {
        private int i;
        private java.util.HashMap hm = new java.util.HashMap();
    }

}

Maven dependency:

<dependency>
    <groupId>com.arturmkrtchyan.sizeof4j</groupId>
    <artifactId>sizeof4j</artifactId>
    <version>0.1.0</version>
</dependency>

Compatibility Badge

sizeof4j's People

Contributors

arturmkrtchyan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.