Skip to content

Instantly share code, notes, and snippets.

@LaruYan
Created February 17, 2017 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LaruYan/26dc7792a9e31e89a6e583941f46ed02 to your computer and use it in GitHub Desktop.
Save LaruYan/26dc7792a9e31e89a6e583941f46ed02 to your computer and use it in GitHub Desktop.
I tried some of screen orientation checks for android and looped that 100,000 times.. The other does same but 240 times slower!
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="is_landscape">true</bool>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="is_landscape">false</bool>
</resources>
long startTime = System.currentTimeMillis();
long sum = 0;
for(int i = 1; i <= 1000000 ; i ++) {
// D/LANDTEST: sum: 500000500000 / time: 32
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
sum += i;
}
// D/LANDTEST: sum: 500000500000 / time: 7743
if (getResources().getBoolean(R.bool.is_landscape)) {
sum += i;
}
}
Log.d("LANDTEST", "sum: " + sum + " / time: " + (System.currentTimeMillis() - startTime));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment