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
| class TestWorker < ApplicationWorker | |
| sidekiq_options retry: false, queue: 'test' | |
| def perform | |
| Sidekiq::Batch.new.tap do |batch| | |
| batch.on(:death, 'TestWorker#on_death') | |
| batch.jobs do | |
| SampleWorker.perform_async | |
| end | |
| end |
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
| { | |
| "query": { | |
| "find": "items", | |
| "filter": { | |
| "parent_id": { | |
| "$oid": "..." | |
| }, | |
| "$or": [ | |
| { | |
| "title": { |
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 'fast_attributes' | |
| require 'virtus' | |
| require 'attrio' | |
| require 'anima' | |
| require 'ethos/entity' | |
| ATTR_NAMES = [:attr0, :attr1, :attr2, :attr3, :attr4, :attr5, :attr6, :attr7, :attr8, :attr9] | |
| class FastIntegers |
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' | |
| Benchmark.bmbm do |bm| | |
| bm.report '1000 x Kernel#load wrap=false' do | |
| 1000.times do | |
| load 'script.rb', false | |
| end | |
| end | |
| bm.report '1000 x Kernel#load wrap=true' 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
| require 'benchmark' | |
| User.all.size | |
| #=> 30000 | |
| # BEFORE | |
| Benchmark.measure { User.all.select { |user| user.firstname =~ /Erol/ } } | |
| #=> 66.630000 1.070000 67.700000 ( 67.868905) | |
| # AFTER |
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' | |
| User.all.size #=> 30000 | |
| Benchmark.bm(30) do |bm| | |
| bm.report 'User Instances' do | |
| User.all | |
| .select { |user| user.lastname.downcase == 'erol' } | |
| end | |
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' | |
| n = 100_000 | |
| Benchmark.bm(10) do |bm| | |
| bm.report('interpolation') { n.times { "#{ 1 }/#{ 2 }" } } | |
| bm.report('concatenation') { n.times { 1.to_s + '/' + 2.to_s } } | |
| end |
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' | |
| s = "" | |
| t = "" | |
| n = 100_000 | |
| Benchmark.bm(10) do |bm| | |
| bm.report('String#+') { n.times { s += "A" } } | |
| bm.report('String#<<') { n.times { t << "A" } } |
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' | |
| def tap_method | |
| result = rand.tap {} | |
| end | |
| def non_tap_method | |
| result = rand | |
| result | |
| end |
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
| http { | |
| if ($request_method = 'POST') { | |
| add_header 'Cache-Control' 'no-cache'; | |
| } | |
| } |
NewerOlder