Skip to content

Instantly share code, notes, and snippets.

View ccocchi's full-sized avatar

Christopher Cocchi-Perrier ccocchi

  • WildCodeSchool
  • Paris, France
  • X @ccocchi
View GitHub Profile
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")
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
}
/**
@ccocchi
ccocchi / bench.rb
Last active August 29, 2015 14:07
Are you my father?
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)
@ccocchi
ccocchi / bench.rb
Created January 6, 2015 11:26
presence? comes at a cost
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
@ccocchi
ccocchi / profanity_benchmark.rb
Created February 7, 2015 14:59
Profanity filter
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_
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,
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'
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) } }
# 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
@ccocchi
ccocchi / bench.rb
Last active May 10, 2019 10:07
Regexp VS start_with?
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 }