|
| 1 | +/* |
| 2 | + * Tencent is pleased to support the open source community by making |
| 3 | + * WCDB available. |
| 4 | + * |
| 5 | + * Copyright (C) 2017 THL A29 Limited, a Tencent company. |
| 6 | + * All rights reserved. |
| 7 | + * |
| 8 | + * Licensed under the BSD 3-Clause License (the "License"); you may not use |
| 9 | + * this file except in compliance with the License. You may obtain a copy of |
| 10 | + * the License at |
| 11 | + * |
| 12 | + * https://opensource.org/licenses/BSD-3-Clause |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | + */ |
| 20 | + |
| 21 | +#import "benchmark_normal.h" |
| 22 | +#import "WCTBenchmarkStaticstic.h" |
| 23 | +#import "WCTBenchmarkObject.h" |
| 24 | + |
| 25 | +void benchmark_normal(NSString* baseDirectory) |
| 26 | +{ |
| 27 | + NSString* className = NSStringFromClass(WCTBenchmarkObject.class); |
| 28 | + NSString* path = [baseDirectory stringByAppendingPathComponent:className]; |
| 29 | + NSString* tableName = className; |
| 30 | + WCTDataBase* database = [[WCTDataBase alloc] initWithPath:path]; |
| 31 | + [database close:^{ |
| 32 | + [database removeFilesWithError:nil]; |
| 33 | + }]; |
| 34 | + |
| 35 | + { |
| 36 | + BOOL ret = [database createTableAndIndexesOfName:tableName |
| 37 | + withClass:WCTBenchmarkObject.class]; |
| 38 | + assert(ret); |
| 39 | + } |
| 40 | + |
| 41 | + int count = 100000; |
| 42 | + { |
| 43 | + NSMutableArray* objects = [[NSMutableArray alloc] init]; |
| 44 | + for (int i = 0; i < count; ++i) { |
| 45 | + WCTBenchmarkObject* object = [[WCTBenchmarkObject alloc] init]; |
| 46 | + object.intValue = i; |
| 47 | + object.stringValue = [NSString stringWithFormat:@"%d", i]; |
| 48 | + [objects addObject:object]; |
| 49 | + } |
| 50 | + WCTTable* table = [database getTableOfName:tableName |
| 51 | + withClass:WCTBenchmarkObject.class]; |
| 52 | + WCTBenchmarkStaticstic* staticstic = [[WCTBenchmarkStaticstic alloc] init]; |
| 53 | + [staticstic start]; |
| 54 | + BOOL ret = [table insertObjects:objects]; |
| 55 | + [staticstic stop]; |
| 56 | + assert(ret); |
| 57 | + NSLog(@"Insert %d objects cost %f ms", count, staticstic.getElapseTimes[0].doubleValue); |
| 58 | + } |
| 59 | + |
| 60 | + { |
| 61 | + WCTTable* table = [database getTableOfName:tableName |
| 62 | + withClass:WCTBenchmarkObject.class]; |
| 63 | + WCTBenchmarkStaticstic* staticstic = [[WCTBenchmarkStaticstic alloc] init]; |
| 64 | + [staticstic start]; |
| 65 | + NSArray* objects = [table getAllObjects]; |
| 66 | + [staticstic stop]; |
| 67 | + NSLog(@"Select %lu objects cost %f ms", objects.count, staticstic.getElapseTimes[0].doubleValue); |
| 68 | + } |
| 69 | +} |
0 commit comments