• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Replace Double.parseDouble();

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got am information that
Double.parseDouble(); is very slow
is any boddy know any replacement for this function
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You can use public Double valueOf()


 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, valueOf() and parseDouble() are virtually identical - the difference is that the former returns a double (primitive) and the latter returns a Double (wrapper class). In fact valueOf() calls the exact same code as parseDouble() internally, and then it creates a Double wrapper for the result, so it will take slightly longer.
Anoop- have you tested parseDouble() yourself to see if it's really too slow for your application? In general I don't see any reason why it should be overly slow; I've never noticed a problem with it. Are you parsing a lot of values, that the time it takes to parse is noticeable? I don't think there's really a good alternative in the standard libraries. You might be able to write something yourself that parses faster than the standard library, if you can assume some additional restrictions on hte input - e.g. no leading or trailing spaces or zeroes; no values that might overflow a double variable; maybe others. But I doubt you'd improve on it by a whole lot, and it would be easy to introduce new bugs into the algorithm. Good luck...
 
Honk if you love justice! And honk twice for tiny ads!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic