GithubHelp home page GithubHelp logo

skip's Introduction

Skip

Optimize your ruby methods using JIT compilation
  
    require "rubygems"
    require "skip"
    
    func = lambda do |i,j|
      r = 0
      while i < j
        i += 2
        j += 1
        r += 1 if j % 2 == 0
      end
      r
    end
    
    opti = Skip::optimized &func

    n = 100
    Benchmark.bm do |x|
      GC.start
      r = x.report{ n.times{ func[2,99999] } }
      GC.start
      jit = x.report{ n.times{ opti[2,99999] } }
      puts "#{(r.real / jit.real).round} times faster"
    end
    
         user     system      total        real
    32.030000   0.020000  32.050000 ( 32.049772)
     0.440000   0.000000   0.440000 (  0.439581)
    73 times faster
  

or

  
    require "rubygems"
    require "skip"
    
    class A
      def fib n
        return a if a <= 1
        fib(n-1) + fib(n-2)
      end
    end

    n = 100
    v = 19
    a = A.new
    
    Benchmark.bm do |x|
      GC.start
      r = x.report{ n.times{ a.fib v } }
      Skip::optimize A, :fib, 1
      GC.start
      jit = x.report{ n.times{ a.fib v } }
      puts "#{(r.real / jit.real).round} times faster"
    end
    
        user     system      total        real
    4.340000   0.880000   5.220000 (  5.216383)
    0.030000   0.000000   0.030000 (  0.027656)
    189 times faster
  

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.