kou commented on code in PR #43882:
URL: https://github.com/apache/arrow/pull/43882#discussion_r1735794640


##########
ruby/red-arrow/lib/arrow/decimal128-array.rb:
##########
@@ -18,7 +18,9 @@
 module Arrow
   class Decimal128Array
     def get_value(i)
-      BigDecimal(format_value(i))
+      string = format_value(i)
+      string.sub!(".E", ".0E") if string.include?(".E")

Review Comment:
   It's slow for non-`0.E` cases. I think that `0.E` case is a rare case. So I 
think that we should prioritize non-`0.E` cases than `0.E` case.
   
   ```ruby
   #!/usr/bin/env ruby
   
   require "benchmark"
   
   n = 100000
   Benchmark.bmbm do |x|
     x.report("0.0E - nothing") do
       n.times do
         string = "0.0E"
         string
       end
     end
   
     x.report("0.E - nothing") do
       n.times do
         string = "0.E"
         string
       end
     end
   
     x.report("0.0E - include?") do
       n.times do
         string = "0.0E"
         string.sub!(".E", ".0E") if string.include?(".E")
         string
       end
     end
   
     x.report("0.E - include?") do
       n.times do
         string = "0.E"
         string.sub!(".E", ".0E") if string.include?(".E")
         string
       end
     end
   
     x.report("0.0E - always sub!") do
       n.times do
         string = "0.0E"
         string.sub!(".E", ".0E")
         string
       end
     end
   
     x.report("0.E - always sub!") do
       n.times do
         string = "0.E"
         string.sub!(".E", ".0E")
         string
       end
     end
   end
   ``` 
   
   ```text
   Rehearsal ------------------------------------------------------
   0.0E - nothing       0.007245   0.000000   0.007245 (  0.007261)
   0.E - nothing        0.006175   0.000441   0.006616 (  0.006616)
   0.0E - include?      0.015160   0.000000   0.015160 (  0.015161)
   0.E - include?       0.064167   0.000000   0.064167 (  0.064181)
   0.0E - always sub!   0.028071   0.000000   0.028071 (  0.028070)
   0.E - always sub!    0.054682   0.000000   0.054682 (  0.054683)
   --------------------------------------------- total: 0.175941sec
   
                            user     system      total        real
   0.0E - nothing       0.006584   0.000000   0.006584 (  0.006584)
   0.E - nothing        0.006586   0.000000   0.006586 (  0.006585)
   0.0E - include?      0.014944   0.000000   0.014944 (  0.014944)
   0.E - include?       0.063128   0.000000   0.063128 (  0.063129)
   0.0E - always sub!   0.027945   0.000000   0.027945 (  0.027946)
   0.E - always sub!    0.054426   0.000000   0.054426 (  0.054426)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to