- (void)addFMDatabaseQueue {
FMDatabaseQueue * queue = [FMDatabaseQueue databaseQueueWithPath:self.dbPath];
// dispatch_queue_t q1 = dispatch_queue_create("queue1", NULL);
// dispatch_queue_t q2 = dispatch_queue_create("queue2", NULL);
dispatch_queue_t q1 = dispatch_queue_create("queue1", DISPATCH_QUEUE_CONCURRENT);
dispatch_queue_t q2 = dispatch_queue_create("queue2", DISPATCH_QUEUE_CONCURRENT);
// 10万条6分钟6秒 插入
// 20万条查询不到2分钟
dispatch_async(q1, ^{
for (int i = 0; i < 100000; ++i) {
[queue inDatabase:^(FMDatabase *db) {
NSString * sql = @"insert into user (name, password) values(?, ?) ";
NSString * name = [NSString stringWithFormat:@"queue111 %d", i];
BOOL res = [db executeUpdate:sql, name, @"boy"];
if (!res) {
debugLog(@"error1 to add db data: %@", name);
} else {
debugLog(@"succ1 to add db data: %@", name);
}
}];
}
});
dispatch_async(q2, ^{
for (int i = 0; i < 100000; ++i) {
[queue inDatabase:^(FMDatabase *db) {
NSString * sql = @"insert into user (name, password) values(?, ?) ";
NSString * name = [NSString stringWithFormat:@"queue222 %d", i];
BOOL res = [db executeUpdate:sql, name, @"boy"];
if (!res) {
debugLog(@"error2 to add db data: %@", name);
} else {
debugLog(@"succ2 to add db data: %@", name);
}
}];
}
});
}
FMDatabaseQueue
最新推荐文章于 2023-02-13 18:51:00 发布