Issue
I have always tried to use the resource in Android to declare my strings in Android, ever since I had a translation issue. But there are times I don't need to declare strings, like the strings I use for log messages. But I did a little search and found that nobody has tested what is faster, loading a string from strings.xml in code or hard coding it in line. Here is the normal way I use log messages:
log.d(TAG, "This is My Hard Coded String");
Compared to putting "This is My Hard Coded String" in strings.xml and then calling it in code:
log.d(TAG, getResurce().getString(R.string.hardcodedstring));
I've tried running some test times these but not sure I have considered all aspects. So what is faster has anyone else done this?
Solution
The Test Results I got were this for Inline code the average time of writing out 100 times to log files was:
20.6 ms
The average time for getResource string call and writing to log file 100 times was:
29.0 ms
I was surprised I thought the getResources() call would be faster.
Answered By - JPM
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.