Android 및 Project의 iOS에서 SQLite 성능 사이에서 벤치 마크를 수행하려고하고 있으며 Android와 비교하여 iOS 플랫폼에서 성능이 상당히 떨어지는 것 같습니다.Android 및 iOS의 SQLite 간의 성능 차이
내가 얻으려고하는 것은 SQLite DB에 여러 행 (5000)을 삽입하고 플랫폼을 비교하는 시간을 측정하는 것입니다. Android의 경우 5000 밀리 초를 수행하는 데 500 밀리미터의 결과를 얻지 만 iOS의 경우 동일한 작업을 20 초 이상 수행합니다. 어떻게 이럴 수있어?
이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, create it
if (sqlite3_open([databasePath UTF8String], &db) == SQLITE_OK){
sql = @"CREATE TABLE IF NOT EXISTS BENCHMARK(ID INTEGER PRIMARY KEY AUTOINCREMENT, TESTCOLUMN TEXT)";
//Create table
if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, NULL) == SQLITE_OK){
NSLog(@"DB created");
}else{
NSLog(@"Failed to create DB");
}
//START: INSERT BENCHMARK
NSDate *startTime = [[NSDate alloc] init];//Get timestamp for insert-timer
//Insert values in DB, one by one
for (int i = 0; i<numEntries; i++) {
sql = [NSString stringWithFormat:@"INSERT INTO BENCHMARK (TESTCOLUMN) VALUES('%@')",[self.dataArray objectAtIndex:i]];
if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, NULL) == SQLITE_OK){
//Insert successful
}
}
//Append time consumption to display string
resultHolder = [resultHolder stringByAppendingString:[NSString stringWithFormat:@"5000 insert ops took %f sec\n", [startTime timeIntervalSinceNow]]];
//END: INSERT BENCHMARK
안드로이드 코드 :
// SETUP
long startTime, finishTime;
// Get database object
BenchmarkOpenHelper databaseHelper = new BenchmarkOpenHelper(getApplicationContext());
SQLiteDatabase database = databaseHelper.getWritableDatabase();
// Generate array containing random data
int rows = 5000;
String[] rowData = new String[rows];
int dataLength = 100;
for (int i=0; i<rows; i++) {
rowData[i] = generateRandomString(dataLength);
}
// FIRST TEST: Insertion
startTime = System.currentTimeMillis();
for(int i=0; i<rows; i++) {
database.rawQuery("INSERT INTO BENCHMARK (TESTCOLUMN) VALUES(?)", new String[] {rowData[i]});
}
finishTime = System.currentTimeMillis();
result += "Insertion test took: " + String.valueOf(finishTime-startTime) + "ms \n";
// END FIRST TEST
테스트 할 안드로이드 장치가 없기 때문에 확실하지 않습니다. 그러나 OS X와 Linux에서 SQLite를 사용한 경험은 OS X이 I/O 차단을 야기하는 "디스크로 플러시"요청을 실제로 받아들이는 반면 Linux는 손을 흔드는 반면 차단하지는 않습니다. 설명 할 수 있습니다. – StilesCrisis
나는 C (iOS) 방식이 Java (Android) 방식보다 약간 빠르다고 생각한다. –
고맙습니다. 나는 동기화의 튜링으로 약간의 속도를 얻었다! – Andain