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/ips' | |
require 'uri' | |
str = 'https://www.facebook.com/' | |
Benchmark.ips do |x| | |
x.report('start_with?') { str.start_with?('https://', 'http://') } | |
x.report('match?') { str.match?(URI::regexp) } | |
x.report('=~') { str =~ URI::regexp } |
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/ips' | |
require 'oj' | |
require File.expand_path(File.join(File.dirname(__FILE__), 'config', 'environment')) | |
require 'elasticsearch-dsl' | |
class Official | |
include Elasticsearch::DSL |
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/ips' | |
array = %w(abc def ghi jkl) | |
ok = %w(abc jkl) | |
bad = %w(abc yio) | |
Benchmark.ips do |x| | |
x.report('& ok') { (array & ok).size == ok.size } | |
x.report('all ok') { ok.all? { |e| array.include?(e) } } |
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 'active_support/concern' | |
require 'active_support/core_ext/object/blank' | |
require 'action_view/buffers' | |
require 'action_view/helpers/output_safety_helper' | |
require 'action_view/helpers/capture_helper' | |
require 'action_view/helpers/tag_helper' | |
require 'benchmark/ips' |
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/ips' | |
module TestMethods | |
def order_by_ids(ids) | |
order("idx(ARRAY#{ids}, id)") | |
end | |
def order_by_ids_string(ids) | |
o = Post.send(:sanitize_sql_array, |
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/ips' | |
text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ullamcorper eleifend velit sed placerat. In libero leo, fringilla ut mauris nec, bibendum varius nisi. Nam rhoncus facilisis lacinia. Integer massa quam, vestibulum eget est sed, elementum vulputate nibh. Mauris fermentum tellus eu commodo blandit. Cras ornare, risus id semper lacinia, est urna maximus dolor, aliquam maximus metus sem a velit. Suspendisse vel libero eu leo volutpat eleifend accumsan nec massa. Integer eu vulputate quam, ac tristique arcu. Fusce et justo vitae nulla maximus lacinia. Integer dolor massa, finibus vel mattis a, porta eu erat. Suspendisse potenti. Sed ex magna, imperdiet sit amet augue ac, vestibulum vehicula mi. Praesent sapien neque, bibendum eget lorem fermentum, molestie semper leo.' | |
words_10 = %w(foo bar string amp baguette marine grenadine quezac bambou panda) | |
words_100 = words_10 * 10 | |
regexp_10 = Regexp.new(words_10.join('|'), Regexp::IGNORECASE) | |
regexp_100 = Regexp.new(words_ |
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/ips' | |
require 'active_support/core_ext/object/blank' | |
find_result = nil | |
result = Benchmark.ips do |x| | |
x.report('==') do |times| | |
i = 0 | |
while i < times | |
1 if find_result == nil |
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/ips' | |
require 'active_support/inflector' | |
require 'set' | |
class A; end | |
class B < A; end | |
klasses = [Struct, A].freeze | |
strings = ['Struct', 'A'].freeze | |
set = Set.new(strings) |
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
case class Metric(id: String, aggregationOperation: AggregationOperation) | |
case class Dimension(id: String) | |
object AggregationOperation extends Enumeration { | |
type AggregationOperation = Value | |
val Sum, Average, Min, Max, Count = Value | |
} | |
/** |
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
import scala.annotation.tailrec | |
import scala.collection.immutable.Seq | |
object Benchmark { | |
def main(args:Array[String]){ | |
val smallSeq = Seq(1, "foo") | |
val twoTypesSeq = ((1 to 100) map (n => 1)) ++ ((1 to 100) map (n => "I am a fucking String")) | |
println("With small seq") |