Reputation: 13
I would like to have a function that returns the processor speed of an iOS device.
I found what I thought might be a solution with this:
#include <CoreService/CoreService.h>
long getProcessorClockSpeed()
{
OSErr err;
long result;
err=Gestalt(gestaltProcClkSpeed,&result);
if (err!=nil)
return 0;
else
return result;
}
but this doesn't compile. (CoreService.h file not found). Apparently, this is for Mac OS and not iOS?
I have written and optimized a signal processing algorithm that can now just barely run in real time on an iPhone 4S. I would like to allow the algorithm to run on dual-core devices with a clock speed of 800 MHz or more, and disallow it on other devices. I am already able to get the number of cores, but I have not been able to get the CPU clock speed.
I could do something like get the model of the device, and then allow or disallow the algorithm on devices based on that string, but that kind of table-based approach would need to be updated as new devices become available or would impose assumptions about new devices.
Is there an idiomatic way for getting the CPU clock speed?
Kudos awarded for: 1) an approach that won't get my app rejected 2) an approach that is less headache than a model-name-table-based approach?
Upvotes: 1
Views: 5576
Reputation: 164311
I am not aware of an supported way to get the clock speed on an iOS device.
You could get the HW model identifier and bake-in a list of models that is too slow, and therefore refuse to run on those models.
The reason I suggest a negative list (models you cannot run on), as opposed to a positive list, is to ensure that your app will run on new, yet unreleased models - they are likely to be fast enough.
The code to get the HW model string is
#include <sys/types.h>
#include <sys/sysctl.h>
- (NSString *) platform
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
return platform;
}
You can find a comprehensive list of current and previous models at the iPhoneWiki, the string you will need to match on is in the Identifier column.
Upvotes: 4