Skip to content

@gthank /micro.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
list_comp vs. map
#! /usr/bin/env python
import timeit
def main():
list_comp_t = timeit.Timer("y = [math.log10(num) for num in x]", setup="import math; x = [1500, 1049.8, 34, 351]")
map_t = timeit.Timer("z = map(math.log10, x)", setup="import math; x = [1500, 1049.8, 34, 351]")
# Use an absurdly high number of reps because the data is tiny and I want the numbers to be on a reasonably human timescale.
print list_comp_t.timeit(1000000)
print map_t.timeit(1000000)
if __name__ == '__main__':
main()
main()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.