Note that there are some explanatory texts on larger screens.

plurals
  1. POEfficient strtod in Java?
    primarykey
    data
    text
    <p>So I have this Java program that I use to munch through several terabytes of data. Performance is a concern.</p> <p>I've profiled the app, and a large fraction of all memory allocations as well as a large fraction of CPU time come from performing one simple operation:</p> <p>I have an array of ASCII chars. I know that the characters from offset <code>i</code> to offset <code>j</code> represent a floating-point number. I need to extract that floating-point number into a <code>double</code>.</p> <p>The naive <code>Double.parseDouble(new String(buf, i, j - i))</code> does the job. However, this is where a lot of time is spent and a lot of memory allocations come from, probably because:</p> <ul> <li><code>new String()</code> creates a new object, creates an internal <code>char[]</code> array and copies the characters into the array;</li> <li><code>Double.parseDouble()</code> creates a <a href="http://www.docjar.com/html/api/sun/misc/FloatingDecimal.java.html" rel="nofollow"><code>FloatingDecimal</code></a> object, and too creates a <code>char[]</code> array, also copying the characters into it.</li> </ul> <p>All these allocations and all this copying are not really necessary. Can I avoid them?</p> <p>What I'd really like is a <a href="http://en.wikipedia.org/wiki/Strtod" rel="nofollow"><code>strtod</code></a>-like function that would take a <code>char[]</code> (or a <code>byte[]</code>) as well as start/end offsets, and return a <code>double</code>.</p> <p>Any suggestions? Should I roll out my own? Should I write a JNI wrapper around <code>strtod</code>? Should I use some Java library that's already out there?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload