Created
          December 3, 2015 10:07 
        
      - 
      
- 
        Save thr3a/0717a9d3a6d5c363fad2 to your computer and use it in GitHub Desktop. 
  
    
      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' | |
| namespace :bulk do | |
| desc "TODO" | |
| task insert: :environment do | |
| Task.delete_all | |
| Benchmark.bm 100 do |r| | |
| r.report "normal" do | |
| 1000.times do |i| | |
| Task.create(title: "#{i}", content: "content #{i}") | |
| end | |
| end | |
| r.report "bulk" do | |
| tasks = [] | |
| 1000.times do |i| | |
| tasks << Task.new(title: "#{i}", content: "content #{i}") | |
| end | |
| Task.import tasks | |
| end | |
| r.report "without validate" do | |
| tasks = [] | |
| 1000.times do |i| | |
| tasks << Task.new(title: "#{i}", content: "content #{i}") | |
| end | |
| Task.import tasks, validate: false | |
| end | |
| r.report "without validate and new" do | |
| tasks = [] | |
| 1000.times do |i| | |
| tasks << ["#{i}", "content #{i}"] | |
| end | |
| Task.import ['title', 'content'], tasks, validate: false | |
| end | |
| end | |
| 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
    
  
  
    
  | mPro:hoge thr3a$ rake bulk:insert | |
| user system total real | |
| normal 1.360000 0.470000 1.830000 ( 2.095945) | |
| bulk 0.310000 0.010000 0.320000 ( 0.317949) | |
| without validate 0.160000 0.000000 0.160000 ( 0.168920) | |
| without validate and new 0.080000 0.000000 0.080000 ( 0.085750) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment