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 — `dup`ing an Identity Hash/Set is faster than creating a new one · Issue #230 · fastruby/fast-ruby

duping an Identity Hash/Set is faster than creating a new one #230

New issue
Copy link
New issue
Copy link
Open
Open
duping an Identity Hash/Set is faster than creating a new one#230
Copy link

Description

@amomchilov
amomchilov
opened on Jul 15, 2024
Issue body actions

It's one less allocation, too :)

YJIT off YJIT on
Set.new.compare_by_identity 2.571M 4.260M
S.dup 3.014M 4.999M
∆ 1.17x 1.17x
YJIT off YJIT on
Hash.new.compare_by_identity 5.643M 8.208M
H.dup 5.988M 9.014M
∆ 1.06x 1.09x
S = Set.new.compare_by_identity.freeze
H = Hash.new.compare_by_identity.freeze

Benchmark.ips do |x|
  x.config(time: 10)

  x.report(".new.compare_by_identity") do |times|
    i = 0
    while (i += 1) <= times
      S.dup
    end
  end
  
  x.report(".dup                    ") do |times|
    i = 0
    while (i += 1) <= times
      Set.new.compare_by_identity
    end
  end
  
  x.compare!
end

Benchmark.ips do |x|
  x.config(time: 10)
  
  x.report(".new.compare_by_identity") do |times|
    i = 0
    while (i += 1) <= times
      H.dup
    end
  end
  
  x.report(".dup                    ") do |times|
    i = 0
    while (i += 1) <= times
      Hash.new.compare_by_identity
    end
  end
  
  x.compare!
end

Activity

  1. JuanVqz commented on Mar 7, 2025

    @JuanVqz
    JuanVqz
    on Mar 7, 2025
    Member
    More actions

    @amomchilov could you please opne a PR?

  2. BigwWinner commented on Aug 12, 2026

    @BigwWinner
    BigwWinner
    on Aug 12, 2026
    More actions

    It's one less allocation, too :)

    YJIT off YJIT on
    Set.new.compare_by_identity 2.571M 4.260M
    S.dup 3.014M 4.999M
    ∆ 1.17x 1.17x
    YJIT off YJIT on
    Hash.new.compare_by_identity 5.643M 8.208M
    H.dup 5.988M 9.014M
    ∆ 1.06x 1.09x
    S = Set.new.compare_by_identity.freeze
    H = Hash.new.compare_by_identity.freeze

    Benchmark.ips do |x|
    x.config(time: 10)

    x.report(".new.compare_by_identity") do |times|
    i = 0
    while (i += 1) <= times
    S.dup
    end
    end

    x.report(".dup ") do |times|
    i = 0
    while (i += 1) <= times
    Set.new.compare_by_identity
    end
    end

    x.compare!
    end

    Benchmark.ips do |x|
    x.config(time: 10)

    x.report(".new.compare_by_identity") do |times|
    i = 0
    while (i += 1) <= times
    H.dup
    end
    end

    x.report(".dup ") do |times|
    i = 0
    while (i += 1) <= times
    Hash.new.compare_by_identity
    end
    end

    x.compare!
    end

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

    No labels
    No labels

    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.