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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:26:34+00:00 2026-05-30T17:26:34+00:00

I have a method which runs incredibly slow testing in device (iPhone3G) comparing to

  • 0

I have a method which runs incredibly slow testing in device (iPhone3G) comparing to simulator.

While the simulator can handle around 100 executions of the method in 1 second the device can only run 4 times thought the method in a second.

What can make it so sloooow?

CODE:
Note: The method calculates a human friendly string from a two dates (start date and end date of an event).

-(void)calculateDiaDeInicioYFinTexto
{
    NSLog(@"inicio");
    NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];

    NSMutableString *auxString = [NSMutableString string];

    NSLocale *currLocale = [NSLocale currentLocale];

    NSString *stringFormatDay = [NSDateFormatter dateFormatFromTemplate:@"d" 
                                                                options:0 
                                                                 locale:currLocale];
    NSString *stringFormatDayMonth = [NSDateFormatter dateFormatFromTemplate:@"dMMMM" 
                                                                     options:0 
                                                                      locale:currLocale];
    NSString *stringFormatDayMonthYear = [NSDateFormatter dateFormatFromTemplate:@"dMMMMYYYY" 
                                                                         options:0 
                                                                          locale:currLocale];

    NSDateFormatter *formatterDay = [[NSDateFormatter alloc] init];
    [formatterDay setDateFormat:stringFormatDay];
    [formatterDay setLocale:currLocale];

    NSDateFormatter *formatterDayMonth = [[NSDateFormatter alloc] init];
    [formatterDayMonth setDateFormat:stringFormatDayMonth];
    [formatterDayMonth setLocale:currLocale];

    NSDateFormatter *formatterDayMonthYear = [[NSDateFormatter alloc] init];
    [formatterDayMonthYear setDateFormat:stringFormatDayMonthYear];
    [formatterDayMonthYear setLocale:currLocale];


    NSCalendar *calendar = [NSCalendar currentCalendar];

    NSDateComponents *dateComponentsNow = [calendar components:(NSYearCalendarUnit |
                                                                NSMonthCalendarUnit | 
                                                                NSDayCalendarUnit)
                                                      fromDate:[NSDate date]];
    NSDateComponents *dateComponentsInicio = [calendar components:(NSYearCalendarUnit |
                                                                   NSMonthCalendarUnit | 
                                                                   NSDayCalendarUnit)
                                                         fromDate:self.diaDeInicio];
    NSDate *diaDeInicioTimeless = [calendar dateFromComponents:dateComponentsInicio];

    NSDateComponents *dateComponentsFin = [calendar components:(NSYearCalendarUnit | 
                                                                NSMonthCalendarUnit |
                                                                NSDayCalendarUnit) 
                                                      fromDate:self.diaDeFin];
    NSDate *diaDeFinTimeless = [calendar dateFromComponents:dateComponentsFin];


    if ( [diaDeInicioTimeless isEqualToDate:diaDeFinTimeless] ) {
        // dates are the same
        if ( dateComponentsInicio.year == dateComponentsNow.year ) {
            // date is in the current year
            [auxString appendFormat:@"%@", [formatterDayMonth stringFromDate:self.diaDeInicio]];
        } else {
            // date is in another year
            [auxString appendFormat:@"%@", [formatterDayMonthYear stringFromDate:self.diaDeInicio]];
        }
    } else {
        // dates are different
        if ( dateComponentsInicio.year == dateComponentsFin.year ) {
            // years are the same
            if ( dateComponentsInicio.month == dateComponentsFin.month ) {
                // Months are the same
                if ( dateComponentsInicio.year == dateComponentsNow.year ) {
                    // date is in the current year
                    [auxString appendFormat:@"%@ - %@", 
                     [formatterDay stringFromDate:self.diaDeInicio],
                     [formatterDayMonth stringFromDate:self.diaDeFin]];                    
                } else {
                    // date is in another year
                    [auxString appendFormat:@"%@ - %@", 
                     [formatterDay stringFromDate:self.diaDeInicio],
                     [formatterDayMonthYear stringFromDate:self.diaDeFin]];                                        
                }
            } else {
                // Months are different
                if ( dateComponentsInicio.year == dateComponentsNow.year ) {
                    // date is in the current year
                    [auxString appendFormat:@"%@ - %@", 
                     [formatterDayMonth stringFromDate:self.diaDeInicio],
                     [formatterDayMonth stringFromDate:self.diaDeFin]];                    
                } else {
                    // date is in another year
                    [auxString appendFormat:@"%@ - %@", 
                     [formatterDayMonth stringFromDate:self.diaDeInicio],
                     [formatterDayMonthYear stringFromDate:self.diaDeFin]];                    
                }
            }
        } else {
            // Years are different
            [auxString appendFormat:@"%@ - %@", 
             [formatterDayMonthYear stringFromDate:self.diaDeInicio],
             [formatterDayMonthYear stringFromDate:self.diaDeFin]];            
        }
    }
    self.diaDeInicioYFinTexto = auxString;
    [formatterDay release];
    [formatterDayMonth release];
    [formatterDayMonthYear release];
    [localPool release]; 

    NSLog(@"Fin");
}
  • 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-05-30T17:26:35+00:00Added an answer on May 30, 2026 at 5:26 pm

    iOS Devices are considerably less powerful than the computer that you are running the simulator on. The iOS simulator does not emulate the ARM proccessor and so it runs it at full speed.

    In addition, the reason that this particular method is so slow is because of the creation of the NSDateFormatter and NSCalendar objects. Those are fairly expensive to create and should be cached in an instance variable/property if you want to use them multiple times.

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

Sidebar

Related Questions

I have an embedded device which runs Java applications which can among other things
I have a method which runs this: Track* track = [[Track alloc] init:[obj objectForKey:@PersistentID]
I have a method which runs several rake commands. Does this method belong in
I have a Hibernate transactional method doImportImpl which runs multi-threaded. Certain records however need
So I have this builder that runs a buildClass method which should be public,
Using VS2010 i have a test that calls a method which runs a command
I have an AsyncTask which calls my LocationHandler class method getLocation() which runs a
I have a Java application which runs on an embedded device. Because different devices
I have an application which runs a long task and returns a value. While
I have a method which runs asynchronously after start, using OutputStream or Writer as

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.