Skip to content

Instantly share code, notes, and snippets.

@yuki24
Last active August 29, 2015 14:18
Show Gist options
  • Save yuki24/a80988f35aceac76f1d5 to your computer and use it in GitHub Desktop.
Save yuki24/a80988f35aceac76f1d5 to your computer and use it in GitHub Desktop.
Levenshtein benchmark
Calculating -------------------------------------
each_char 924.000 i/100ms
each_codepoint 1.381k i/100ms
-------------------------------------------------
each_char 9.320k (± 5.1%) i/s - 47.124k
each_codepoint 13.857k (± 3.6%) i/s - 70.431k
Comparison:
each_codepoint: 13857.4 i/s
each_char: 9319.5 i/s - 1.49x slower

With #each_codepoint

Total allocated 320

Total retained 1

allocated memory by gem

 51200  did_you_mean/lib

allocated memory by file

 51200  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb

allocated memory by location

 25600  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:11
 12800  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:17
 12800  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15

allocated objects by gem

   320  did_you_mean/lib

allocated objects by file

   320  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb

allocated objects by location

   160  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:11
    80  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:17
    80  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15

retained memory by gem

   160  did_you_mean/lib

retained memory by file

   160  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb

retained memory by location

   160  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15

retained objects by gem

     1  did_you_mean/lib

retained objects by file

     1  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb

retained objects by location

     1  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15

Allocated String Report

Retained String Report

With #each_char

Total allocated 21920

Total retained 2

allocated memory by gem

1868800  did_you_mean/lib

allocated memory by file

1868800  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb

allocated memory by location

1728000  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
 115200  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14
  25600  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:11

allocated objects by gem

 21920  did_you_mean/lib

allocated objects by file

 21920  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb

allocated objects by location

 20400  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
  1360  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14
   160  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:11

retained memory by gem

   160  did_you_mean/lib

retained memory by file

   160  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb

retained memory by location

    80  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
    80  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

retained objects by gem

     2  did_you_mean/lib

retained objects by file

     2  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb

retained objects by location

     1  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
     1  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

Allocated String Report

  2560  "_"
  2400  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
   160  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

  2560  "e"
  2400  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
   160  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

  2480  "g"
  2400  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
    80  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

  1360  "s"
  1200  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
   160  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

  1360  "n"
  1200  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
   160  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

  1360  "i"
  1200  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
   160  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

  1280  "r"
  1200  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
    80  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

  1280  "u"
  1200  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
    80  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

  1280  "?"
  1200  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
    80  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

  1280  "d"
  1200  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
    80  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

  1200  "user_logged_in?"
  1200  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15

  1200  "o"
  1200  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15

  1200  "l"
  1200  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15

    80  "user_signed_in?"
    80  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

Retained String Report

     1  "user_signed_in?"
     1  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:14

     1  "user_logged_in?"
     1  /GitHub/did_you_mean/lib/did_you_mean/levenshtein.rb:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment