# Float vs int performance

**URL:** <https://discuss.elastic.co/t/float-vs-int-performance/9633>\
**Category:** Elasticsearch\
**Created:** [November 8, 2012, 4:02pm UTC](https://discuss.elastic.co/t/float-vs-int-performance/9633 "2012-11-08T16:02:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 8, 2012, 4:02pm UTC](https://discuss.elastic.co/t/float-vs-int-performance/9633/1 "2012-11-08T16:02:25Z")

</div>

I am in the midst of tuning my ElasticSearch cluster. One major issue is  
memory and some of the main culprits are facets over float values. To be  
more precise, lots of distinct range facets over fields that contain prices  
(11.99, 2139.00, 0.01, etc.). These ranges are combined on the client side  
and mimic dynamic ranges.

Both ints and floats are 4 bytes. One common practice is to never use  
floating points for currency due to rounding errors, but there are no  
arithmetic operations performed on these values. Plus, I don't want to  
convert legacy code. 🙂 Is there any performance to be had from switching  
values from floats to ints and performing divide by 100.0 on the client  
side? I guess this question mainly pertains to Lucene since it deals with  
the internal caches. The results can also be sorted on these values.

Cheers,

Ivan

--

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [November 9, 2012, 1:11am UTC](https://discuss.elastic.co/t/float-vs-int-performance/9633/2 "2012-11-09T01:11:32Z")

</div>

Hi Ivan,

I don't think there is a significant difference but you should go for your  
own benchmark and get some results until you're satisfied. If it's crazy  
fast with floats and crazy faster with ints, it's still crazy fast 🙂

Cheers,  
Jörg

On Thursday, November 8, 2012 5:02:31 PM UTC+1, Ivan Brusic wrote:

> I am in the midst of tuning my Elasticsearch cluster. One major issue is  
> memory and some of the main culprits are facets over float values. To be  
> more precise, lots of distinct range facets over fields that contain prices  
> (11.99, 2139.00, 0.01, etc.). These ranges are combined on the client side  
> and mimic dynamic ranges.
> 
> Both ints and floats are 4 bytes. One common practice is to never use  
> floating points for currency due to rounding errors, but there are no  
> arithmetic operations performed on these values. Plus, I don't want to  
> convert legacy code. 🙂 Is there any performance to be had from switching  
> values from floats to ints and performing divide by 100.0 on the client  
> side? I guess this question mainly pertains to Lucene since it deals with  
> the internal caches. The results can also be sorted on these values.
> 
> Cheers,
> 
> Ivan

--

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [November 9, 2012, 8:23am UTC](https://discuss.elastic.co/t/float-vs-int-performance/9633/3 "2012-11-09T08:23:05Z")

</div>

On Friday, November 9, 2012 2:11:32 AM UTC+1, Jörg Prante wrote:

> Hi Ivan,
> 
> I don't think there is a significant difference but you should go for your  
> own benchmark and get some results until you're satisfied. If it's crazy  
> fast with floats and crazy faster with ints, it's still crazy fast 🙂

If it's crazy fast with floats and crazy faster with ints, it's still crazy  
fast 🙂 \<== where did you get that from 🙂

> Cheers,  
> Jörg
> 
> On Thursday, November 8, 2012 5:02:31 PM UTC+1, Ivan Brusic wrote:
> 
> > I am in the midst of tuning my Elasticsearch cluster. One major issue is  
> > memory and some of the main culprits are facets over float values. To be  
> > more precise, lots of distinct range facets over fields that contain prices  
> > (11.99, 2139.00, 0.01, etc.). These ranges are combined on the client side  
> > and mimic dynamic ranges.
> > 
> > Both ints and floats are 4 bytes. One common practice is to never use  
> > floating points for currency due to rounding errors, but there are no  
> > arithmetic operations performed on these values. Plus, I don't want to  
> > convert legacy code. 🙂 Is there any performance to be had from switching  
> > values from floats to ints and performing divide by 100.0 on the client  
> > side? I guess this question mainly pertains to Lucene since it deals with  
> > the internal caches. The results can also be sorted on these values.
> > 
> > Cheers,
> > 
> > Ivan

--

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 9, 2012, 4:50pm UTC](https://discuss.elastic.co/t/float-vs-int-performance/9633/4 "2012-11-09T16:50:55Z")

</div>

I'd figured as much, especially in terms of memory, which is my primary  
bottleneck. Code changes would be too many to do a quick benchmark. Wish I  
was near crazy fast!

On Thu, Nov 8, 2012 at 5:11 PM, Jörg Prante [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:

> Hi Ivan,
> 
> I don't think there is a significant difference but you should go for your  
> own benchmark and get some results until you're satisfied. If it's crazy  
> fast with floats and crazy faster with ints, it's still crazy fast 🙂
> 
> Cheers,  
> Jörg
> 
> On Thursday, November 8, 2012 5:02:31 PM UTC+1, Ivan Brusic wrote:
> 
> > I am in the midst of tuning my Elasticsearch cluster. One major issue is  
> > memory and some of the main culprits are facets over float values. To be  
> > more precise, lots of distinct range facets over fields that contain prices  
> > (11.99, 2139.00, 0.01, etc.). These ranges are combined on the client side  
> > and mimic dynamic ranges.
> > 
> > Both ints and floats are 4 bytes. One common practice is to never use  
> > floating points for currency due to rounding errors, but there are no  
> > arithmetic operations performed on these values. Plus, I don't want to  
> > convert legacy code. 🙂 Is there any performance to be had from switching  
> > values from floats to ints and performing divide by 100.0 on the client  
> > side? I guess this question mainly pertains to Lucene since it deals with  
> > the internal caches. The results can also be sorted on these values.
> > 
> > Cheers,
> > 
> > Ivan
> 
> --

--

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:05am UTC](https://discuss.elastic.co/t/float-vs-int-performance/9633/5 "2017-07-06T03:05:07Z")

</div>


