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 9054177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:37:14+00:00 2026-06-16T13:37:14+00:00

I have a XML in my App bundle. I am parsing this XML file.

  • 0

I have a XML in my App bundle. I am parsing this XML file. I parsed this XML using NSXMLParser and using following ways:

  1. running the whole code serially on main thread
  2. Using dispatch queues (GCD):

    2.1 Creating my own dispatch queue using dispatch_queue_create

    2.2 using global queue with High Priority dispatch_get_global_queue

    2.3 using global queue with Low Priority

    2.4 using global queue with Background Priority

  3. using NSOperationQueue

I checked the performance and total time taken in execution of parsing the XML file and found really weird (or may be correct) results.

Following are the codes for above mentioned Parsing ways:

  1. Serial execution on main thread – Execution time 34 msec.

    BOOL success = [conf parseXMLFile:[[NSBundle mainBundle] pathForResource:@"Configuration" ofType:@"xml"] didFailWithError:&error];
    if (success) {
        DLog(@"Parsing Complete");
    }
    else
        DLog(@"Parse error %@",[error description]);
    

2.1 Using dispatch_queue_create – Execution time 68 msec.

dispatch_queue_t backgroundQueue = dispatch_queue_create("BackQueue", NULL);

dispatch_async(backgroundQueue, ^{
    NSError *error = nil;
    BOOL success = [conf parseXMLFile:[[NSBundle mainBundle] pathForResource:@"Configuration" ofType:@"xml"] didFailWithError:&error];
    if (success) {
        DLog(@"Parsing Complete");
    }
    else
        DLog(@"Parse error %@",[error description]);
});

dispatch_release(backgroundQueue);

2.2 using global queue with High Priority dispatch_get_global_queue – Execution time – 74 msec

dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);

dispatch_async(backgroundQueue, ^{
    NSError *error = nil;
    BOOL success = [conf parseXMLFile:[[NSBundle mainBundle] pathForResource:@"Configuration" ofType:@"xml"] didFailWithError:&error];
    if (success) {
        DLog(@"Parsing Complete");
    }
    else
        DLog(@"Parse error %@",[error description]);
});

dispatch_release(backgroundQueue);

2.3 Similarly as 2.2 Using global queue with LOW Priority DISPATCH_QUEUE_PRIORITY_LOW – Execution time – 72 msec

2.4 Similarly as 2.2 Using global queue with BACKGROUND Priority DISPATCH_QUEUE_PRIORITY_BACKGROUND – Execution time – 37 msec

2.5. Using NSOperationQueue (subclassing the NSOperation) – Execution time – 36 msec

Can anyone help me figure out these execution times and why are they so strange (or am I missing something). Why I am getting the best performance with method 1.
Why is DISPATCH_QUEUE_PRIORITY_BACKGROUND giving better performance than HIGH.
Why is NSOperationQueue giving better results than GCD?

  • 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-16T13:37:15+00:00Added an answer on June 16, 2026 at 1:37 pm

    Update:

    I tested the various dispatch and operation queues for for two scenarios:

    1. Invoke a single job that repeatedly parse a large (725kb) XML file 100 times in a single operation; and

    2. Queue 100 operations to parse the same very large XML file one time each.

    My results (measured in seconds) on my iPhone 5 were as follows:

    1. For first scenario:

      Main queue: 18.7
      NSOperation: 18.4
      Global high-priority queue: 18.3
      Global default-priority queue: 18.4
      Global low-priority queue: 18.4
      Global background queue: 18.5
      Serial dispatch queue: 18.3
      
    2. For my second scenario:

      Main queue: 18.7
      NSOperation: 10.9
      Global high-priority queue: 10.9
      Global default-priority queue: 10.8
      Global low-priority queue: 10.8
      Global background queue: 11.0
      Serial dispatch queue: 18.5
      

    So I draw two fairly unsurprising conclusions from this:

    • For a computationally intensive background operation at the very least, there did not appear to be much variation between the various concurrent background techniques;

    • When breaking a task into multiple operations, the concurrent background operations (NSOperationQueue, GCD global queues) enjoyed a performance advantage over the serial operations.

    I’m not suggesting, though, that a device under resource contention might not exhibit different behavior in terms of scheduling (notably GCD global queue types, see dispatch_queue_priority_t, would affect the scheduling of operations with other concurrent operations queued on the device). I’m only trying to demonstrate empirically that the various queues are not significantly more or less efficient than each other. Having said that, I personally wouldn’t use DISPATCH_QUEUE_PRIORITY_HIGH in my apps as I assume that would have the possibility of affecting core iOS functionality.

    Also, in the interest of full disclosure, I should admit that I’m focusing on material performance differences. It is quite possible that one mechanism or another might offer performance differences measured in msec. When I’m considering different approaches for background performance, I’m definitely more focused on user-observable performance differences.


    Original Answer:

    I invoked my parseManyTimes (which repeatedly parses a large XML file) from the main queue:

    [self parseManyTimes:@"Main queue"];
    

    Via NSOperation:

    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [queue addOperationWithBlock:^{
         [self parseManyTimes:@"NSOperation"];
    }];
    queue = nil;
    

    Via global queues on GCD:

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self parseManyTimes:@"DISPATCH_QUEUE_PRIORITY_DEFAULT"];
    });
    

    and

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        [self parseManyTimes:@"DISPATCH_QUEUE_PRIORITY_HIGH"];
    });
    

    and

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        [self parseManyTimes:@"DISPATCH_QUEUE_PRIORITY_LOW"];
    });
    

    and via a GCD serial queue:

    dispatch_queue_t dispatchQueue = dispatch_queue_create("org.rob.test", NULL);
    dispatch_async(dispatchQueue, ^{
        [self parseManyTimes:@"dispatch_queue_create"];
    });
    

    and the results did not differ significantly from each other (all between 32.2 and 32.5 seconds each). My parsing routine is:

    - (void)parseManyTimes:(NSString *)type
    {
        NSDate *startDate = [NSDate date];
        for (NSInteger i = 0; i < 100; i++)
            [self parse];
    
        NSLog(@"%@: %.1f", type, [[NSDate date] timeIntervalSinceDate:startDate]);
    }
    
    - (void)parse
    {
        NSURL *url = [[NSBundle mainBundle] URLForResource:@"personnel" withExtension:@"xml"];
        NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
        parser.delegate = self;
        [parser parse];
    }
    

    I ran this on an iPad on a 725kb XML file. Clearly, the way I’ve structured this, with a very time consuming process, it will tend to was out any negligible variance in how the various queues are dispatched, but rather focus on the background operation. By it doesn’t raise any concerns (for me at least) in material performance issues in the various techniques.

    The results were:

    Main queue: 32.3
    NSOperation: 32.2
    DISPATCH_QUEUE_PRIORITY_DEFAULT: 32.4
    DISPATCH_QUEUE_PRIORITY_HIGH: 32.3
    DISPATCH_QUEUE_PRIORITY_LOW: 32.5
    dispatch_queue_create: 32.3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: package com.problemio; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View;
I have a Flex-app.xml. The actual manifest in the apk file seems to be
I have an xml layout for a Fragment (android.support.v4.app.Fragment). When this Fragment is added
I have an xml file I need to modify: ... </web-app> I want to
Situation I have a fairly simple app with 2 layouts using SharedPreferences. Main.xml Settings.xml
I have the following actvity. package org.dewsworld.ui; import android.app.Activity; import android.os.Bundle; import android.util.Log; import
I have got the code: package com.finalyearproject.cookmefood; import android.app.Activity; import android.os.Bundle; import android.widget.ListView; import
I have written this code to parse this xml: http://hiscentral.cuahsi.org/webservices/hiscentral.asmx/GetSeriesCatalogForBox2 But when I run
I have an XML view in a rails app, and need to insert in
I have a .xml file in my App_Data folder, I can access it fine

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.