EduardoMaia
EduardoMaia

Reputation: 601

benchmarking battery android

I'm making a face recog app and I want to do a little benchMarking in it. Want some help in measuring the battery. I was trying something like this:

    public float calcBattery(float init){
        float batteryValue;
        int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
        int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
        batteryValue = (init - (level / (float)10000));
        if (batteryValue<0) batteryValue*=-1;
        return batteryValue;
    }

but since my application runs in 2 to 17 seconds depending on the number of faces the batter level always appear to be unchanged. I want to know if there is a proper way to do battery benchmarking on android without a third party.

Thanks in advance

Edit:

I wanted to have some way of measuring battery more precise then the level of the battery, like mA for instance. And I don't have a clue as how to measure in mA, but I know is possible since there are apps that do it like that.

Upvotes: 1

Views: 127

Answers (1)

Joey Harwood
Joey Harwood

Reputation: 981

To do any benchmarking with real significance you're going to need to run your app for a lot longer than that. You should be able to include a loop that will continue running until a given percentage point is passed or you could just make a break loop button. My suggestion would be to aim for going from 90% to 10% or so. One thing about battery life indicators is that they're non-linear -- Is Battery Life Linear?. Additionally, you should make sure that as many other apps and background processes (non system critical) are disabled to eliminate the chance that some other app is eating your battery.

Keep track of how long it takes for the battery to drain from 90% to 10%. If you divide the time by 80 then you have how long on average it takes for the app to use one percentage point worth of battery life.

Let's use some made up numbers to make that math more concrete. Say after 1 hour exactly the batter goes from 90% to 10%. An hour is 3600 seconds. 3600 / 80 = 45. So on average every 45 seconds your app used 1% of the battery life.

Keep in mind that there are a variety of devices, so it would be better to repeat this on a couple different devices of varying quality.

One more thing to keep in mind. If your app is intensive enough to start heating up the phone more than just to warm when left running (which I think might happen with face recognition), then the battery will start to drain quicker as it gets hot. If this is the case, you should probably try doing a lot of shorter trials (maybe 5% at a time). It's not ideal, because it adds more chance for error, but may be necessary. You would be dividing by 5 instead of 80 in this case and then averaging together your trials.

Upvotes: 1

Related Questions