私は新しい ios であり、ios 上のマルチスレッドである NSThread のパフォーマンスがわかりません。私には機能があります
-(void) writeBlock:(NSString *)srcPath toPath:(NSString *)destPath fromIndex:(int)fIndex toIndex:(int)tIndex
{
//create file handle for srcPath and destPath
for(int i=fIndex;i<=tIndex;i++){
//read from source filehandle
//write to dest filehandle
}
//close filehandle.
}
上記の関数に対して単一のスレッドを作成すると、この関数を実行する時間は 1 秒です。しかし、私が作成するとき:
for(int i=0;i<20;i++)
{
[NSThread detachNewThreadSelector: @selector(writeBlock:) toTarget:self withObject:myObject];
//for each thread, tIndex-fIndex is the same with tIndex-fIndex of single above thread
}
20 スレッドの実行時間は 13 ~ 16 秒です。時間は1~5秒くらいになると思います。マルチスレッドって遅いですか?誰でも私を助けることができますか?どうもありがとう