This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| string = "HELLO WÖRLD WHÜTS ÄP?" | |
| n = 500_000 | |
| # Using String#tr in one fell swoop | |
| tr_single = ->(n, str) { n.times { str.tr('A-ZÄÜÖ', 'a-zäüö') } } | |
| # Chaining outputs of String#tr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Latin1Convert do | |
| @doc """ | |
| Convert an input HTML string to UTF-8 unicode. | |
| """ | |
| @spec call(String.t) :: String.t | |
| def call(html) do | |
| content_type = content_type_from_header(html) | |
| cond do | |
| content_type == :latin1 -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # frozen_string_literal: true | |
| require 'benchmark' | |
| input = "This::Is::One::Heavily::Nested::Module" | |
| n = 1_000_000 | |
| Benchmark.bm do |benchmark| | |
| benchmark.report("String#split") do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # frozen_string_literal: true | |
| require 'minitest/autorun' | |
| require 'date' | |
| class MaybeDate < SimpleDelegator | |
| include Comparable | |
| def initialize(date = nil, default: 9999) | |
| date = begin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'thread' | |
| WORKERS = 3 | |
| queue = SizedQueue.new(WORKERS * 2) | |
| # Backlog some work! Using a separate thread since push operation on | |
| # SizedQueue may block when it's "full" | |
| Thread.new { MyModel.find_in_batches { |batch| queue << batch } } | |
| readio, writeio = IO.pipe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Ruby version: 2.6.1 | |
| Run with: `ruby pirate_combo.rb` | |
| user system total real | |
| nested map, small array 0.009232 0.000084 0.009316 ( 0.009315) | |
| nested map, huge array 27.279118 0.510522 27.789640 ( 27.790889) | |
| flat map, small array 0.002179 0.000043 0.002222 ( 0.002219) | |
| flat map, huge array 12.483256 0.087956 12.571212 ( 12.571798) | |
| Array#product, small array 0.001514 0.000000 0.001514 ( 0.001513) | |
| Array#product, huge array 5.079583 0.000002 5.079585 ( 5.080144) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/makefile b/makefile | |
| index 8d6c5d7..2db6c5f 100644 | |
| --- a/makefile | |
| +++ b/makefile | |
| @@ -5,8 +5,8 @@ ifeq ($(LIB),libusb) | |
| CPPFLAGS=-Dlibusb | |
| LIBS=-lusb-1.0 | |
| else | |
| - CPPFLAGS=-Dhidapi | |
| - LIBS=-lhidapi-hidraw |
OlderNewer