Alphabets Benchmarks - How many ways to unaccent a t ext string? Turn AÄÁaäá into AAAaaa. And the winner is.. .

Gerald Bauer <[email protected]> Tue, 13 Aug 2019 22:17:57 +0200
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAAxEZd8eq5qH=S8kTtSa+D54MEG+E04MQ4cgTreiavM-eYK=4A@mail.gmail.com>
Hello,

  let's try out half a dozen ways to unaccent a text string? [1]

  The challenge - What's the fastest way to turn `AÄÁaäá EÉeé IÍiíï
NÑnñ OÖÓoöó Ssß UÜÚuüú`
  into `AAAaaa EEee IIiii NNnn OOOooo Ssss UUUuuu`?

  Let's benchmark and the winner (so far) is... Spoiler: `gsub` .

    NON_ALPHA_CHAR_REGEX = /[^A-Za-z0-9 ]/    # use/try regex constant
for speed-up
    def unaccent_gsub( text, mapping )
      text.gsub( NON_ALPHA_CHAR_REGEX ) do |ch|
        mapping[ch] || ch
      end
    end


  Can you find a faster way? Show us.

  Happy data (and text) wrangling with ruby. Cheers. Prost.

[1]: https://github.com/sportdb/sport.db/tree/master/alphabets/benchmark

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>