Giter VIP home page Giter VIP logo

how-to-concat-in-rails's Introduction

The purpose of this repo is to explore different alternative to concat strings in database

Setup

bundle install
bundle exec rake db:create db:migrate db:seed

Benchmark

bundle exec rake benchmark:run
bundle exec rake benchmark:memory

Output of benchmark

Results obtained with 650k records in db

Time

       user     system      total        real
Using .map 10.848756   1.556344  12.405100 ( 12.750942)
Using .pluck  1.501343   0.159192   1.660535 (  1.809598)
Using Raw SQL  2.774949   0.409105   3.184054 (  3.425237)
Using Arel  2.602465   0.726804   3.329269 (  3.509664)
Using Scenic  0.358593   0.030825   0.389418 (  0.628602)
Using virtual column  0.295781   0.041697   0.337478 (  0.452611)

Memory

Calculating -------------------------------------
          Using .map     1.792B memsize (     1.530B retained)
                        14.987M objects (    12.969M retained)
                        50.000  strings (    50.000  retained)
        Using .pluck   620.559M memsize (    22.757k retained)
                         9.635M objects (   134.000  retained)
                        50.000  strings (    50.000  retained)
       Using Raw SQL   903.172M memsize (     2.488k retained)
                        10.504M objects (    24.000  retained)
                        50.000  strings (     9.000  retained)
          Using Arel   903.177M memsize (     3.100k retained)
                        10.504M objects (    18.000  retained)
                        50.000  strings (    11.000  retained)
        Using Scenic   273.213M memsize (    45.049k retained)
                         2.627M objects (   217.000  retained)
                        50.000  strings (    50.000  retained)
Using virtual column   273.161M memsize (    22.365k retained)
                         2.626M objects (   124.000  retained)
                        50.000  strings (    50.000  retained)

Comparison:
Using virtual column:  273160735 allocated
        Using Scenic:  273212736 allocated - 1.00x more
        Using .pluck:  620559199 allocated - 2.27x more
       Using Raw SQL:  903172270 allocated - 3.31x more
          Using Arel:  903176602 allocated - 3.31x more
          Using .map: 1792250836 allocated - 6.56x more

how-to-concat-in-rails's People

Contributors

just-the-v avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.