Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9196365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:50:06+00:00 2026-06-17T21:50:06+00:00

I’m wondering if anyone has some insight into what would perform better: doing a

  • 0

I’m wondering if anyone has some insight into what would perform better: doing a core data fetch or looking for the file on disk.

The situation I’m in is downloading records and each record has an image tied to it. But different records can have the same image so I don’t want to download the image twice. I’m saving the images to disk and using an NSManagedObject to save the web url and the local file path.

To avoid making another network call I can

A: Perform a core data fetch to see if I have the image already based on the web url

NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass([Image class])];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"web_url == %@", myRecord.image_url];

B: Look for the image data on disk from the local file path

NSFileManager *fileManager = [NSFileManager defaultManager];
NSData *photoData = [fileManager contentsAtPath:myRecord.photo_path];

Additionally is there something in Instruments that would allow me to time these? It would be a handy tool to know how to use in the future. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:50:07+00:00Added an answer on June 17, 2026 at 9:50 pm

    I finally got around to testing this with the help of from a user submitted Macro for Measuring Execution Time in this NSHipster article http://nshipster.com/reader-submissions-new-years-2013/.

    The code being tested was as follows

    __block NSData *photoData;
    const char *caller = "filemanager";
    MVComputeTimeWithNameAndBlock(caller, ^{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    photoData = [fileManager contentsAtPath:[self createLocalFilePath:myRecord.photo_path]];
    });
    
    caller = "coredata";
    MVComputeTimeWithNameAndBlock(caller, ^{
        NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass([Image class])];
        fetchRequest.predicate = [NSPredicate predicateWithFormat:@"web_url == %@", myRecord.image_url];
        NSError *error;
        NSArray *arr = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&error];
        if([arr count]){
            Image *photo = arr[0];
        }
    });
    

    2013-01-25 14:31:06.359 FormulaOne[26554:12b03] filemanager – Time Running is: 0.000325
    2013-01-25 14:31:06.359 FormulaOne[26554:12b03] coredata – Time Running is: 0.000491
    2013-01-25 14:31:11.958 FormulaOne[26554:12b03] filemanager – Time Running is: 0.000178
    2013-01-25 14:31:11.959 FormulaOne[26554:12b03] coredata – Time Running is: 0.000417
    2013-01-25 14:31:14.840 FormulaOne[26554:12b03] filemanager – Time Running is: 0.000187
    2013-01-25 14:31:14.841 FormulaOne[26554:12b03] coredata – Time Running is: 0.000421
    2013-01-25 14:33:10.869 FormulaOne[26554:12b03] filemanager – Time Running is: 0.000193
    2013-01-25 14:33:10.870 FormulaOne[26554:12b03] coredata – Time Running is: 0.000540
    2013-01-25 14:33:13.087 FormulaOne[26554:12b03] filemanager – Time Running is: 0.000170
    2013-01-25 14:33:13.088 FormulaOne[26554:12b03] coredata – Time Running is: 0.000392

    I switched it over to

    int count = [[self managedObjectContext] countForFetchRequest:fetchRequest error:&error];
    

    because I don’t actually need the object, I just need to know of its existence. The timing was actually worse.

    2013-01-25 14:36:27.760 FormulaOne[28209:12b03] filemanager – Time Running is: 0.000346
    2013-01-25 14:36:27.761 FormulaOne[28209:12b03] coredata – Time Running is: 0.000601
    2013-01-25 14:36:29.978 FormulaOne[28209:12b03] filemanager – Time Running is: 0.000182
    2013-01-25 14:36:29.979 FormulaOne[28209:12b03] coredata – Time Running is: 0.000479
    2013-01-25 14:36:31.585 FormulaOne[28209:12b03] filemanager – Time Running is: 0.000265
    2013-01-25 14:36:31.586 FormulaOne[28209:12b03] coredata – Time Running is: 0.000400
    2013-01-25 14:36:34.923 FormulaOne[28209:12b03] filemanager – Time Running is: 0.000307
    2013-01-25 14:36:34.924 FormulaOne[28209:12b03] coredata – Time Running is: 0.001055
    2013-01-25 14:36:36.038 FormulaOne[28209:12b03] filemanager – Time Running is: 0.000318
    2013-01-25 14:36:36.040 FormulaOne[28209:12b03] coredata – Time Running is: 0.000740

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.