Sha256: a24b9bc192d52698af642039d742a0b65c84c89e8cbc4544186073dfefd30ae4
Contents?: true
Size: 1.27 KB
Versions: 6
Compression:
Stored size: 1.27 KB
Contents
require 'lazy_resource' require 'benchmark' LazyResource.configure do |config| config.site = "https://api.github.com" end class User include LazyResource::Resource end class Repo include LazyResource::Resource attribute :id, Fixnum attribute :pushed_at, DateTime attribute :owner, User attribute :clone_url, String attribute :name, String attribute :description, String end class User include LazyResource::Resource self.primary_key_name = 'login' attribute :id, Fixnum attribute :login, String attribute :name, String attribute :bio, String attribute :company, String attribute :number_of_public_repos, Fixnum, :from => 'public_repos' attribute :repos, [Repo] end dhh = User.find('dhh') dhh.repos.each do |repo| puts "#{dhh.name} pushed to #{repo.name} on #{repo.pushed_at.strftime("%D")}" end puts "Fetching 10 users serially..." Benchmark.bm do |x| x.report do names = [] 10.times do |i| u = User.find(i + 1) names << u.name end puts names end end puts "\nFetching 10 users in parallel..." Benchmark.bm do |x| x.report do users = [] 10.times do |i| users << User.find(i + 1) end puts users.map { |user| user.name } end end
Version data entries
6 entries across 6 versions & 1 rubygems