Category: Apple IPhone2012-06-28 11:31 4664 people read reviews (0) favorite reports iOS Language Manager Test C
C Language Implementation
#include "Sys/stat.h"
-(Long Long) Filesizeatpath: (nsstring*) filepath{
struct STAT st;
if (Lstat ([FilePath cstringusingencoding:nsutf8stringencoding], &st) = = 0) {
return st.st_size;
}
return 0;
}
Objective-c Language Implementation
-(Long Long) Filesizeatpath: (nsstring*) filepath{
nsfilemanager* manager = [Nsfilemanager Defaultmanager];
if ([manager Fileexistsatpath:filepath]) {
return [[Manager Attributesofitematpath:filepath Error:nil] fileSize];
}
return 0;
}
If we loop the two methods 1000 times, we can find a huge performance gap between them, in my test environment, the results are as follows, the C function is only 5% of the OC method, in this recommendation C language
An empty folder which gets the size of 68k, should be the system file bar, if you know people, welcome message
iOS about file operations get file size