From: pawelniewiadomski@... Date: 2017-03-19T11:19:15+00:00 Subject: [ruby-core:80231] [Ruby trunk Bug#13330] Array.include? is slow for symbols Issue #13330 has been reported by pawelniewie (Pawel Niewiadomski). ---------------------------------------- Bug #13330: Array.include? is slow for symbols https://bugs.ruby-lang.org/issues/13330 * Author: pawelniewie (Pawel Niewiadomski) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16] * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- Looking at the code I noticed that [:test].include?(:test) goes through a general path instead using an optimised version making searching slower than for strings: Benchmark available at https://github.com/pawelniewie/benchmark-set-array-contains/blob/master/ruby/array_include.rb Comparison: array: 1332567.6 i/s array symbols: 1154135.9 i/s - 1.15x slower I created a fix for that, after changes you get following results: Comparison: array symbols: 1630417.3 i/s array: 1372269.7 i/s - 1.19x slower -- https://bugs.ruby-lang.org/ Unsubscribe: