DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Low GC in Java: Using primitives

Low GC in Java: Using primitives

Peter Lawrey user avatar by
Peter Lawrey
·
Jul. 11, 11 · Java Zone · Interview
Like (0)
Save
Tweet
6.64K Views

Join the DZone community and get the full member experience.

Join For Free

in a recent article i examined how using primitives and collections which support primitives natively instead of wrappers and standard collections can reduce memory usage and improve performance.

different way to have a map of int/integer

there are a number of ways you can use int/integer and a number of collections you store them in. depending on which approach you use can have a big difference on the performance and the amount of garbage produced.
test performance range memory used
use integer wrappers and hashmap 71 - 134 (ns) 53 mb/sec
use int primitives and hashmap 45 - 76 (ns) 36 mb/sec
use int primitives and fastmap 58 - 93 (ns) 28 mb/sec
use int primitives and tintinthashmap 18 - 28 (ns) nonimal
use int primitives and simple hash map 6 - 9 (ns) nonimal
the performance range was the typical (50%tile) and one of the higher (98%tile) timings. the garbage was the result of 900,000 loops per second.


these tests were run on my new system.

the code

loop tested
int runs = 300 * 300;
for (int i = 0; i < runs; i++) {
    int x = i % 300;
    int y = i / 300;
    int times = x * y;
    integer count = counters.get(times);
    if (count == null)
        counters.put(times, 1);
    else
        counters.put(times, count + 1);
}
directory of performance examples

from http://vanillajava.blogspot.com/2011/07/low-gc-in-java-using-primitives.html

Java (programming language) garbage collection Data Types Memory (storage engine) Testing Garbage (computer science) Data structure Directory

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • An Overview of 3 Java Embedded Databases
  • Modernizing Testing With Data Pipelines
  • Testing Under the Hood Or Behind the Wheel
  • Selenium vs. Protractor: What's the Difference?

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo