저는 새로운 IOS입니다. IOS에서 다중 스레드 인 NSThread의 성능을 알지 못합니다. 제가 상기 기능을위한 단일 스레드를 생성하는 경우 I 함수를다중 스레드가 느립니까?
-(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 초가 될 것 같습니다. 멀티 스레드가 느린가요? 아무도 도와 줄 수 있습니까? 고마워요
새 스레드를 생성하는 데 약간의 오버 헤드가 있습니다. 또한 이러한 모든 스레드가 파일 시스템 (아마도 동일한 파일)에서 읽으려는 경우 파일 시스템 액세스를 위해 추가 오버 헤드가 발생합니다. – UIAdam