ios - Weird measurment speeds: writing to disc -



ios - Weird measurment speeds: writing to disc -

i've got .zip file in bundle. i'm reading via:

nsfilemanager *filemanager = [[nsfilemanager alloc] init]; filemanager.delegate = self; nsstring *documentspath = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) firstobject]; nsarray *bundlezipfile = [[nsbundle mainbundle] pathsforresourcesoftype:@"zip" indirectory:nil]; nsstring *filepath = [bundlezipfile firstobject]; nsdata *file = [filemanager contentsatpath:filepath]; if ([filemanager fileexistsatpath:filepath] && file) { dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^(void) { nsdictionary *attributes = [filemanager attributesofitematpath:filepath error:nil]; double filesizeinbytes = [attributes[nsfilesize] doublevalue]; nsdate *startdate = [nsdate date]; [filemanager copyitematpath:filepath topath:copy1filepath error:nil]; double timepassed1ms = [startdate timeintervalsincenow] * -1000.0; [filemanager copyitematpath:copy1filepath topath:copy2filepath error:nil]; double timepassed2ms = [startdate timeintervalsincenow] * -1000.0; [filemanager copyitematpath:copy2filepath topath:copy3filepath error:nil]; double timepassed3ms = [startdate timeintervalsincenow] * -1000.0; [filemanager createfileatpath:copy4filepath contents:file attributes:nil]; double timepassed4ms = [startdate timeintervalsincenow] * -1000.0; [filemanager createfileatpath:copy5filepath contents:file attributes:nil]; double timepassed5ms = [startdate timeintervalsincenow] * -1000.0; [filemanager createfileatpath:copy6filepath contents:file attributes:nil]; double timepassed6ms = [startdate timeintervalsincenow] * -1000.0; [file writetofile:copy7filepath atomically:yes]; double timepassed7ms = [startdate timeintervalsincenow] * -1000.0; dispatch_async(dispatch_get_main_queue(), ^(void) { // here calculate times double bytespersecond = filesizeinbytes / timepassed3ms; double mbps = bytespersecond / 1000000.0; }); }); }

i wanted test saving speed on ios. after seeing results i'm confused:

filesize: 88375520.000000 method: copyitematpath:topath:error: copying 1 took: 1460.937977 milliseconds copying 2 took: 1770.565987 milliseconds copying 3 took: 1747.061014 milliseconds total copying took: 4978.564978 bytes per second: 17751.203489 mb/s: 0.017751 method: createfileatpath:contents:attributes: save 1 took: 3752.479970 milliseconds save 2 took: 2313.687027 milliseconds save 3 took: 3230.316997 milliseconds total saving took: 9296.483994 bytes per second: 9506.338102 mb/s: 0.009506 method: writetofile:atomically: bytes per second: 32301.891362 mb/s: 0.032302

so seems, keeping info in buffer , saving slower reading file , saving file :/. more i've tried run 3 first actions (only copyitematpath:topath:error:) , results much better:

filesize: 88375520.000000 method: copyitematpath:topath:error: copying 1 took: 14.973998 milliseconds copying 2 took: 3.435016 milliseconds copying 3 took: 2.867997 milliseconds total copying took: 21.277010 bytes per second: 4153568.483964 mb/s: 4.153568

i've achieved here ~12 mb/s when cpu free.

can please tell me why copying faster saving , why 3 actions faster 3 out of 7..?

ios objective-c iphone performance nsfilemanager

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -