Created
July 25, 2012 19:54
-
-
Save gthank/3178199 to your computer and use it in GitHub Desktop.
list_comp vs. map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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