CBLDatabase *database = [[CBLManager sharedInstance] 
databaseNamed:@"test" error:nil];

            CBLView *v1 = [database viewNamed:viewName];

            [v1 setMapBlock:MAPBLOCK({emit (nil, doc[kDocumentID]);}) 
version:@"1.0"];

            CBLQuery *q1 = [v1 createQuery];

            CBLQueryEnumerator *enumerator = [q1 run:nil];

            NSMutableArray *documentIDs = [NSMutableArray array];

            

            CBLQueryRow *row = nil;

            while ((row = [enumerator nextRow]) != nil)

            {

                id documentID = [row value];

                [documentIDs addObject:documentID];

            }

            

            double beforeSingleFetch = [NSDate 
timeIntervalSinceReferenceDate];

            NSMutableArray *singleFetch = [NSMutableArray array];

            for (NSString *documentID in documentIDs)

            {

                CBLDocument *singleFetchDocument = [database documentWithID:
documentID];

                [singleFetch addObject:singleFetchDocument];

            }

            double afterSingleFetch = [NSDate timeIntervalSinceReferenceDate
];

            double singleFetchDuration = afterSingleFetch - 
beforeSingleFetch;

            

            double beforeBulkFetch = [NSDate timeIntervalSinceReferenceDate
];

            NSMutableArray *bulkFetch = [NSMutableArray array];

            [database inTransaction:^BOOL{

               

                for (NSString *documentID in documentIDs)

                {

                    CBLDocument *bulkFetchDocument = [database 
documentWithID:documentID];

                    [bulkFetch addObject:bulkFetchDocument];

                }

                return YES;

            }];

            double afterBulkFetch = [NSDate timeIntervalSinceReferenceDate];

            double bulkFetchDuration = afterBulkFetch - beforeBulkFetch;

            

            NSAssert(singleFetchDuration > bulkFetchDuration, @"A bulk 
fetch should be faster!");

I understand that the test is super naive, there's caching involved that 
would render the test useless. However, does cbl do bulk fetches? Is that 
what a transaction is for in this case?

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/7d3841bf-7031-4e20-8807-957d1c10d95c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to