On Fri, 3 Nov 2023 23:34:49 GMT, Claes Redestad <redes...@openjdk.org> wrote:

> > @cl4es Could you please test 
> > [this](https://github.com/plokhotnyuk/jsoniter-scala/blob/ba6f4f80deaf0e7a1a95787321de3cc2a232d66d/jsoniter-scala-core/jvm/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala#L3687)
> >  function too? It seems that when testing divisibility by 100 we can use 
> > just one multiplication operation.
> 
> For int values it seems that makes it a few percent faster (1,061 ± 0,017 
> ops/us), though we need a variant that works for longs (`GregorianCalendar` 
> could use this as-is, but not `Year`). Do you have a reference to how they 
> arrived at these numbers? It might be straightforward to extend it to long 
> values, and it'd be good to have the theory to reference either way.

Thanks for trying and giving the honest feedback!

I don't recall exactly but it seems was a kind of playing with `bool f(int n) { 
return n % 100 == 0; }` on the https://godbolt.org to see assembly generated by 
latest c++ compilers with `-O3` option and then brute force squeezing a 
redundant shift operation.

I'm not sure that similar is possible for `long` values, so probably it worth 
to have 2 different methods for `long` and `int` types. I'm even not sure if 
that function would work for negative `int` values.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/16491#issuecomment-1793267652

Reply via email to