On Wed, Dec 9, 2009 at 12:57 AM, will leinweber
<
will.le...@gmail.com> wrote:
> The class method #all on your BlogPost subclass is building actual instances
> of BlogPost, and handing you an array of them.
> Running the view directly is just returning you the data from couchdb
> straight in a hash.
So I tried adding the BlogEntry initialization to the direct view
call. Here's the comparison again:
>> Benchmark.measure { BlogEntry.all.size }
=> #<Benchmark::Tms:0x1125243e8 @real=1.90700101852417, @utime=1.41,
@cstime=0.0, @cutime=0.0, @total=1.55, @label="", @stime=0.14>
>> Benchmark.measure { COUCH.view("BlogEntry/all")["rows"].collect {|r| BlogEntry.new(r)}.size }
=> #<Benchmark::Tms:0x1123ff008 @real=0.162764072418213,
@utime=0.100000000000001, @cstime=0.0, @cutime=0.0,
@total=0.120000000000002, @label="", @stime=0.0200000000000005>
The time taken by the direct view call nearly doubles when I add the
initialization as well, but it's still much faster than the
BlogEntry.all call.
> On Wed, Dec 9, 2009 at 2:04 AM, Shajith <
deme...@gmail.com> wrote:
>> Here's an irb session:
>>
>> >> Benchmark.measure { BlogEntry.all.size }
>> => #<Benchmark::Tms:0x111f03090 @real=1.65944004058838, @utime=1.19,
>> @cstime=0.0, @cutime=0.0, @total=1.33, @label="", @stime=0.14>
>> >> Benchmark.measure { COUCH.view("BlogEntry/all").size }
>> => #<Benchmark::Tms:0x111e23378 @real=0.121485948562622,
>> @utime=0.0700000000000003, @cstime=0.0, @cutime=0.0,
>> @total=0.0700000000000003, @label="", @stime=0.0>
>>
>> BlogEntry is the ExtendedDocument, and COUCH is the database I created
>> using a call like this:
>>
>> COUCH = CouchRest.database!("
http://127.0.0.1:5984/couchrest-test")
BTW: I am using version 0.33 of the gem.
Shajith
PS: I meant to send numbers for the by_tag view, but sent the "all"
numbers instead, sorry about the confusion. The disparity exists in
either, none the less.