Created
          November 8, 2019 23:47 
        
      - 
      
 - 
        
Save AO8/28ca66b51ebb655f32dc19bd01c54fd3 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
AO8 created this gist
Nov 8, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ import random import timeit TAX_RATE = .08 txns = [random.randrange(100) for _ in range(10000000)] def get_price(txn): return txn * (1 + TAX_RATE) def get_prices_with_map(): return list(map(get_price, txns)) def get_prices_with_comprehension(): return [get_price(txn) for txn in txns] def get_prices_with_loop(): prices = [] for txn in txns: prices.append(get_price(txn)) return prices timeit.timeit(get_prices_with_map, number=10) # 19.529933099999994 timeit.timeit(get_prices_with_comprehension, number=10) # 21.178829399999984 timeit.timeit(get_prices_with_loop, number=10) # 25.403499799999963