nicolargo/glances — pull request #456 by desbma (2014-12-11 19:35:33+00:00)
Title: Code simplifications for performance and readability

Some code simplifications, which improve readability, and performance in some cases:
* Sort list in place (`list.sort(...)`) instead of building a new one (`list = sorted(list, ...)`)

* Don't construct empty lists in tests

* Use operator.itergetter from stdlib instead of a lambda when possible. This should speedup sorting big iterables because operator.itergetter fetches the item in the native interpreter insead of evaluating the lambda Python code for each object.
On my machine operator.itemgetter is ~50% faster than a lambda:
> $ python -m timeit -s "d = [{str(i): i for i in range(200)}] * 100" "tuple(map(lambda x: x['101'], d))"
> 100000 loops, best of 3: 13.3 usec per loop
> $ python -m timeit -s "d = [{str(i): i for i in range(200)}] * 100; import operator" "tuple(map(operator.itemgetter('101'), d))"
> 100000 loops, best of 3: 7.11 usec per loop

* Remove some code duplication