Skip to content

Instantly share code, notes, and snippets.

@felixyz
Created May 15, 2024 18:18
Show Gist options
  • Save felixyz/7151d6acc1ef3d0d674caeacc9538862 to your computer and use it in GitHub Desktop.
Save felixyz/7151d6acc1ef3d0d674caeacc9538862 to your computer and use it in GitHub Desktop.
require "bmg"
require "benchmark"
a_domain = (0..10_000).to_a
b_domain = %w[a b c d e f g h i j k l m n o p q]
puts "Generate relations..."
rels = (0..1_000).map do |n|
n_tuples = n == 0 ? 100_000 : 100
Bmg::Relation.new((1..n_tuples).map do
{ a: a_domain.sample, b: b_domain.sample }
end)
end
puts "Generate derived relation"
minus = rels.drop(1).inject(rels[0]) do |agg, r|
agg.minus(r)
end
puts "Perform operations"
result = nil
puts Benchmark.measure { result = minus.to_a }
puts "Tuples left: #{result.count}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment