0

I need to do the following: - Take a text file. - Read the first word of each line and count each kind using a hashmap. - Make the result reach a server.

My question is, what do you think is more battery efficient?

  1. Parsing the file on the Android device and sending the resulting hashmap to the server.

  2. Sending the complete file to the server (compressing with gzip) and doing the parsing online. The retrieving the result to the phone again.

** file sizes can go from 100kB to 5MB

I have already implemented option A, which works well: parsing is done within milliseconds even for big files.

Sending the results, which is just a list of 200 integers, takes slightly longer.

jimmym715
  • 1,512
  • 1
  • 16
  • 25
gatti
  • 1,083
  • 1
  • 11
  • 25

2 Answers2

1

Gut feeling says that because the parse sounds simple, and networking is expensive, you should do the calculations on the phone.

But really, there is only one way to find out, because the situation (files, parsing needs etc) is the main issue here, is to test. Run tests. Multiple. Report back what you find out :D

Nanne
  • 64,065
  • 16
  • 119
  • 163
0

I am not providing stable results. My experiment only consisted in trying both alternatives 50 times in a row, and listening for battery changes.

The results are pretty similar in both cases which are: - Parsing a 1MB file in the phone and sending the result, and wait for OK (50 times) - Sending the 1MB file to the server, parsing it there and getting back the result. I was hoping to get better results on offline parsing, and they actually slightly are, but they are not significantly better. After several tests, even sometimes online parsing was better.

Parsing simply consists in reading the first word of each line and storing it in a Map. All network communications were done through WIFI.

As results are pretty similar, offline parsing is better in this case, because you don't have to rely on a network connection. Still if anyone else is facing the same problem, I would suggest testing both alternatives as I did, because I feel results may vary largely from case to case.

gatti
  • 1,083
  • 1
  • 11
  • 25
  • If it's close on wifi, it will be way different on cell network, something else to keep in mind (and I mean parsing offline will be way better if using cell networks) – Drake Clarris May 09 '12 at 14:44