Skip to content

Instantly share code, notes, and snippets.

@lewispb
Last active February 25, 2022 17:19
Show Gist options
  • Select an option

  • Save lewispb/577db0cf4c75a23f6e07101df3c3488b to your computer and use it in GitHub Desktop.

Select an option

Save lewispb/577db0cf4c75a23f6e07101df3c3488b to your computer and use it in GitHub Desktop.

Revisions

  1. lewispb revised this gist Feb 25, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions kredis_bench.rb
    Original file line number Diff line number Diff line change
    @@ -19,8 +19,8 @@
    unique_list_legacy = Kredis.unique_list_legacy "uniquelist_list"

    # Populate the lists with some initial data
    unique_list.append((1..100_000).map(&:to_s))
    unique_list_legacy.append((1..100_000).map(&:to_s))
    unique_list.append((1_000..100_000).map(&:to_s))
    unique_list_legacy.append((1_000..100_000).map(&:to_s))

    Benchmark.bm do |benchmark|
    benchmark.report("unique_list (sorted set)") do
  2. lewispb created this gist Feb 25, 2022.
    40 changes: 40 additions & 0 deletions kredis_bench.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    # frozen_string_literal: true

    require "bundler/inline"

    gemfile(true) do
    source "https://rubygems.org"

    git_source(:github) { |repo| "https://github.com/#{repo}.git" }

    gem "rails"
    gem "kredis", github: "lewispb/kredis", branch: "unique_list_with_sorted_set"
    end

    Kredis.configurator = Class.new { def config_for(name) { db: "1" } end }.new

    $VERBOSE = nil

    unique_list = Kredis.unique_list "uniquelist_sortedset"
    unique_list_legacy = Kredis.unique_list_legacy "uniquelist_list"

    # Populate the lists with some initial data
    unique_list.append((1..100_000).map(&:to_s))
    unique_list_legacy.append((1..100_000).map(&:to_s))

    Benchmark.bm do |benchmark|
    benchmark.report("unique_list (sorted set)") do
    1_000.times do |n|
    unique_list.append(n)
    end
    end

    benchmark.report("unique_list (list)") do
    1_000.times do |n|
    unique_list_legacy.append(n)
    end
    end
    end

    unique_list.del
    unique_list_legacy.del