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

  • SEARCH
  • Home
  • 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 8865809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:36:47+00:00 2026-06-14T16:36:47+00:00

Basically I have a graph view controller (several in fact) in my iPhone Application.

  • 0

Basically I have a graph view controller (several in fact) in my iPhone Application. The graphs are dependent upon the user selection of different ‘scorecards’. The problem however, is that the user may select as many scorecards as they want: They could select hundreds.

In producing the graph, I have many algorithms running and they are quite heavy duty as they reach into core data to extract information, and example of one of my algorithms is below.

-(NSDictionary *) stablefordForEachPersonOnCourse:(NSString *) courseName atDate:(NSString *) date
{

NSDictionary *shotsForEachPersonOnCourse = [[NSDictionary alloc]initWithDictionary:[self shotsForEachPersonOnCourse:courseName atDate:date]];
CoreDataHelper *helper = [[CoreDataHelper alloc]init];
NSMutableDictionary *stablefordWithNames = [[NSMutableDictionary alloc]init];

ScoreCard *card = [helper getScoreCardWithDate:date fromCourse:[helper getGolfCourseWithName: courseName]];

 for (int j = 0 ; j < [[shotsForEachPersonOnCourse allKeys]count]; ++j) {

     Player *player = [helper getPlayerWithName:[[shotsForEachPersonOnCourse allKeys]objectAtIndex:j] fromScoreCard:card];

     NSString *teeColour = player.teePlayed;
     NSArray *arrayOfHolesPlayed = [helper getOrderedArrayOfHolesFromPlayer:player];
     NSArray *arrayOfHoles = [helper getOrderedArrayOfHolesFromTee:[helper getTeeWithColour:teeColour fromCourse:[helper getGolfCourseWithName:courseName]]];
     NSMutableArray *stableFord = [[NSMutableArray alloc]init];

     for (int i = 0; i< [arrayOfHolesPlayed count]; i++) {

         HolePlayed *holePlayed = [arrayOfHolesPlayed objectAtIndex:i];
         Hole *hole = [arrayOfHoles objectAtIndex:i];

         int temp1 = 0, shotsGet = 0;

         int handicap = player.handicap.intValue;
         int strokeIndex = hole.holeSI.intValue;
         int par = hole.holePar.intValue;
         int shotScore = holePlayed.holeScore.intValue;

         if (shotScore >0) {
         while (temp1 >= 0) {

             if(handicap - (strokeIndex + (18*temp1))>= 0)
             {
                 ++shotsGet;
                 ++temp1;
             }
             else temp1 = -1;

         }
         int stableford = (0 - (shotScore - (shotsGet + par))+2);
         if (stableford < 0) {
             stableford = 0;
         }

        [stableFord addObject:[NSNumber numberWithInt:stableford]];
         }
         else if (shotScore <1) [stableFord addObject:[NSNumber numberWithInt:0]];
     }

     [stablefordWithNames setValue:stableFord forKey:[[shotsForEachPersonOnCourse allKeys]objectAtIndex:j]];
     }
return stablefordWithNames;}  

This algorithm calculates the stableford for each person on the particular scorecard. Now when the user selects many scorecards I need a way of rapidly increasing the speed of algorithms such as these.

I have left this question quite open ended – but what is the best way to speed up my code. Obviously, using Grand Central Dispatch (GCD) is a must as this enables the code to run on different cores thus increasing processing power per unit time – but what would be the best way to use GCD on this? Also, should I be turning all my calculations into blocks? Would this make a significant improvement to the speed of calculation?

  • 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-14T16:36:49+00:00Added an answer on June 14, 2026 at 4:36 pm

    I have left this question quite open ended – but what is the best way to speed up my code?

    Don’t begin by throwing more threads at the problem. You should start by focusing on what is taking the most time:

    • CPU?
    • I/O? (incl. CoreData)
    • Can better algorithms be used?
    • Searching? Sorting?
    • High number of object creation?
    • Can portions of the program be easily expressed using C?

    Then bring those down as much as is reasonable (iterate), then re-evaluate. If you’ve not optimized your implementation yet, then it is typical to achieve significant gains (e.g. 2x-20x or more) from an initial implementation (while keeping it more maintainable than a concurrent/multithreaded implementation). You may benefit from multithreading, but that should be one of your last resorts, especially if your implementation was not designed for concurrent execution (is not threadsafe).

    Obviously, using Grand Central Dispatch (GCD) is a must…

    Making a correct multithreaded implementation can take a lot of time, and can also consume/introduce a lot of hardware resource demands unnecessarily. Even so, there are alternatives to GCD.

    (If you should perform the work on a secondary thread for UX, that’s not just throwing more threads at the problem.)

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

Sidebar

Related Questions

I have been trying to integrate Open Graph into my website. It is basically
I have a DirectShow filter graph in my Delphi 6 application built with the
Is it possible to generate a global call graph of an application? Basically I
I have this chart graph I am working on, basically is a set of
I have a fairly complex method in my controller that basically outputs data to
Hi I have a need to create a Ternary Plot graph from 3 different
I have written a networked game (basically a prototype) which implements different smoothing algorithms
In Graph, there is a triangular strip problem. Basically, we have a set of
I basically have a program that filters records from one excel file to another
I basically have three tables, posts, images and postimages (this simply contains the ids

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.