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 > Reading/writing GC-less memory

Reading/writing GC-less memory

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

Join the DZone community and get the full member experience.

Join For Free

How you access data can make a difference to the speed. Whether you use manual loop unrolling or let the JIT do it for you can also make a difference to performance.
I have included C++ and Java tests doing the same thing for comparison.

Tests

In each case, different approaches to storing 16 GB of data were compared.

In the following tests I compared storing data
  • allocating, writing to, reading from and total GC times
  • byte[] (smallest primitive) and long[] (largest primitive)
  • arrays, direct ByteBuffer and Unsafe
  • JIT optimised and hand unrolled four times

storetypesizeunrolledallocatewritingreadingGC time
C++ char[]native8-bit charno31 μs12.0 s8.7 sN/A
C++ char[]native8-bit charyes5 μs8.8 s6.6 sN/A
C++ long long[]native64-bit intno11 μs4.6 s1.4 sN/A
C++ long long[]native64-bit intyes12 μs4.2 s1.2 sN/A
byte[]heapbyteno4.9 s20.7/7.8 s7.4 s51 ms
byte[]heapbyteyes4.9 s7.1 s8.5 s44 ms
long[]heaplongno4.7 s1.6 s1.5 s37 ms
long[]heaplongyes4.7 s1.5 s1.4 s45 ms
ByteBufferdirectbyteno4.8 s18.1/10.0 s14.0 s6.1 ms
ByteBufferdirectbyteyes4.8 s12.2/10.0 s16.7 s6.1 ms
ByteBufferdirectlongno4.7 s6.0/3.9 s2.4 s6.1 ms
ByteBufferdirectlongyes4.6 s4.7/2.3 s7.9 s6.1 ms
Unsafedirectbyteno10 μs18.2 s13.8 s6.0 ms
Unsafedirectbyteyes10 μs8.7 s8.3 s6.0 ms
Unsafedirectlongno10 μs5.2 s1.9 s6.0 ms
Unsafedirectlongyes10 μs4.2 s1.3 s6.0 ms

C++ test configuration

All tests were performed with gcc 4.5.2 on ubuntu 11.04, compiled with -O2

Java test configuration

All test were performed with Java 6 update 26 and Java 7 update 0, on a fast PC with 24 GB of memory. Timings are for 6/7. Where there one value they were the same.

All tests were run with the options -mx23g -XX:MaxDirectMemorySize=20g -verbosegc

Curiosity

For me the most curious result was the performance of the long[] which was very fast in Java, faster than using C++ or Unsafe directly.

The code

C++ tests - memorytest/main.cpp

Java tests - MemoryTest.java

 

From http://vanillajava.blogspot.com/2011/08/readingwriting-gc-less-memory.html

Testing Memory (storage engine) Data Types

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Determine if Microservices Architecture Is Right for Your Business
  • Datafaker: An Alternative to Using Production Data
  • Ultra-Fast Microservices: When Microstream Meets Payara
  • How to Generate Fake Test Data

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