GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Methods defined with `define_method` are slower to call · Issue #22 · fastruby/fast-ruby

Methods defined with define_method are slower to call #22

New issue
Copy link
New issue
Copy link
Open
Open
Methods defined with define_method are slower to call#22
Copy link
Labels
Suggestion

Description

@janko
janko
opened on Feb 25, 2015
Issue body actions

While define_method indeed defines methods slighly faster than module_eval, I think it should be noted that calling methods defined with define_method is slower than calling module_eval ones (because define_method creates a closure):

require "benchmark/ips"

object = Class.new {
  module_eval "def evaled_method; end"
  define_method(:defined_method) {}
}.new

Benchmark.ips do |x|
  x.report("module_eval")   { object.evaled_method }
  x.report("define_method") { object.defined_method }
  x.compare!
end
Calculating -------------------------------------
         module_eval    98.664k i/100ms
       define_method    93.809k i/100ms
-------------------------------------------------
         module_eval      6.794M (± 8.1%) i/s -     33.743M
       define_method      4.588M (± 6.7%) i/s -     22.889M

Comparison:
         module_eval:  6793763.3 i/s
       define_method:  4587570.1 i/s - 1.48x slower

I think you benefit more from a method being faster to call than faster to define.

Activity

  1. mateusdeap commented on Sep 27, 2022

    @mateusdeap
    mateusdeap
    on Sep 27, 2022
    Contributor
    More actions

    I wonder in which category this should go into? Any opinions, @ashwinisukale ?

  2. ashwinisukale
    added
    Suggestion
    on Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Suggestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.