我正在尝试在一个项目的Android和iOS的SQLite性能之间进行基准测试,与Android相比,iOS平台上的性能似乎真的很差。
我要实现的目标是测量将行数(5000)插入SQLite DB并在平台之间进行比较的时间。对于Android,我大约需要500毫秒才能执行所有5000次插入操作,但对于iOS,相同的操作需要20秒钟以上的时间。怎么会这样?
这是我的iOS代码的片段(插入部分),dataArray是具有5000个随机100个字符的NSStrings的数组:
int numEntries = 5000;
self.dataArray = [[NSMutableArray alloc] initWithCapacity:numEntries];//Array for random data to write to database
//generate random data (100 char strings)
for (int i=0; i<numEntries; i++) {
[self.dataArray addObject:[self genRandStringLength:100]];
}
// Get the documents directory
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
// Build the path to the database file
NSString *databasePath = [[NSString alloc] initWithString:[docsDir stringByAppendingPathComponent: @"benchmark.db"]];
NSString *resultHolder = @"";
//Try to open DB, if file not present, …Run Code Online (Sandbox Code Playgroud)