SlideShare a Scribd company logo
1 of 50
Promise make your python code faster by promising to behave yourself Ryan Kelly [email_address]
[object Object]
The How
The Why
[object Object]
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total timeit: 83
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 l_items = items while i < len( l_items ): total += calculate( l_items[i] ) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.invariant([“items”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.invariant([“items”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total timeit: 83   73
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate( len=len ): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.constant([“len”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.constant([“len”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total timeit: 83   77.1
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): x = items[i] total += 3*x*x - 2*x + (1 / x) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.constant([“calculate”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.constant([“calculate”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total timeit: 83   60.5
items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.invariant([“items”]) @promise.constant([“len”,“calculate”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.sensible() def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total promise.sensible()(globals())
items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total promise.sensible()(globals()) timeit: 83   56.5
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): return sum(calculate(i) for i in items)
items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): return sum(calculate(i) for i in items) timeit: 83   59
items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.sensible() def aggregate(): return sum(calculate(i) for i in items)
items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.sensible() def aggregate(): return sum([calculate(i) for i in items]) timeit: 83   42.6
[object Object]
byteplay http://code.google.com/p/byteplay/ don't hack bytecode without it
>>> a = 1 >>> def add_a(b): ...  return a + b ...  >>>
>>> a = 1 >>> def add_a(b): ...  return a + b ...  >>>  >>> >>> dis.dis(add_a) LOAD_GLOBAL  0 (a) LOAD_FAST  0 (b) BINARY_ADD  RETURN_VALUE  >>>
>>> a = 1 >>> @promise.invariant([&quot;a&quot;]) ... def add_a(b): ...  return a + b ...  >>>
>>> a = 1 >>> @promise.invariant([&quot;a&quot;]) ... def add_a(b): ...  return a + b ...  >>>  >>>  >>> dis.dis(add_a) LOAD_GLOBAL  0 (a) STORE_FAST  1 (_promise_var1_a) LOAD_FAST  1 (_promise_var1_a) LOAD_FAST  0 (b) BINARY_ADD  RETURN_VALUE  >>>
>>> a = 1 >>> @promise.constant([&quot;a&quot;]) ... def add_a(b): ...  return a + b ...  >>>
>>> a = 1 >>> @promise.constant([&quot;a&quot;]) ... def add_a(b): ...  return a + b ...  >>>  >>>  >>> dis.dis(add_a) LOAD_CONST  1 (1) LOAD_FAST  0 (b) BINARY_ADD
>>> a = 1 >>> def calc(): ...  return add_a(7) ...  >>> def add_a(b): ...  return a + b ...  >>>
>>> a = 1 >>> def calc(): ...  return add_a(7) ...  >>> def add_a(b): ...  return a + b ...  >>>  >>> dis.dis(calc) LOAD_GLOBAL  0 (add_a) LOAD_CONST  1 (7) CALL_FUNCTION  1 RETURN_VALUE  >>>
>>> a = 1 >>> @promise.constant([&quot;add_a&quot;]) ... def calc(): ...  return add_a(7) ...  >>> @promise.pure() ... def add_a(b): ...  return a + b ...  >>>
>>> a = 1 >>> @promise.constant([&quot;add_a&quot;]) ... def calc(): ...  return add_a(7) ...  >>> @promise.pure() ... def add_a(b): ...  return a + b ...  >>>  >>> dis.dis(calc) LOAD_CONST  1 ( <function apply_deferred_promises> ) LOAD_CONST  2 (<function calc>) CALL_FUNCTION  1 POP_TOP   LOAD_GLOBAL  0 (add_a) LOAD_CONST  3 (7) CALL_FUNCTION  1 RETURN_VALUE  >>>
>>> calc._promise_deferred [<promise.constant object at 0xb77a5b0c>] >>>
>>> calc._promise_deferred [<promise.constant object at 0xb77a5b0c>] >>> >>> calc() 8 >>>
>>> calc._promise_deferred [<promise.constant object at 0xb77a5b0c>] >>> >>> calc() 8 >>>  >>> dis.dis(calc) LOAD_CONST  1 (7) STORE_FAST  0 (_promise_var3_b) LOAD_CONST  2 (1) LOAD_FAST  0 (_promise_var3_b) BINARY_ADD  JUMP_ABSOLUTE  16 RETURN_VALUE  >>>
[object Object]
For fun!
For fun! None of my production code is CPU-bound
[object Object]
[object Object]
You probably don't need to optimise  that

More Related Content

What's hot

Program Language - Fall 2013
Program Language - Fall 2013 Program Language - Fall 2013
Program Language - Fall 2013 Yun-Yan Chi
 
The Chain Rule, Part 2
The Chain Rule, Part 2The Chain Rule, Part 2
The Chain Rule, Part 2Pablo Antuna
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFTimur Safin
 
Data structures lab
Data structures labData structures lab
Data structures labRagu Ram
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeStripe
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeMongoDB
 
Power shell object
Power shell objectPower shell object
Power shell objectLearningTech
 
関数プログラミングことはじめ revival
関数プログラミングことはじめ revival関数プログラミングことはじめ revival
関数プログラミングことはじめ revivalNaoki Kitora
 
Java binary subtraction
Java binary subtractionJava binary subtraction
Java binary subtractionCharm Sasi
 
Useful javascript
Useful javascriptUseful javascript
Useful javascriptLei Kang
 
Algorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical FileAlgorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical FileKushagraChadha1
 
ゼロから始めるScala文法
ゼロから始めるScala文法ゼロから始めるScala文法
ゼロから始めるScala文法Ryuichi ITO
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Dr. Volkan OBAN
 
chap 2 Ex#1.1
chap 2 Ex#1.1chap 2 Ex#1.1
chap 2 Ex#1.1Ans Ali
 
Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonChristoph Matthies
 
Everything is composable
Everything is composableEverything is composable
Everything is composableVictor Igor
 

What's hot (20)

Program Language - Fall 2013
Program Language - Fall 2013 Program Language - Fall 2013
Program Language - Fall 2013
 
The Chain Rule, Part 2
The Chain Rule, Part 2The Chain Rule, Part 2
The Chain Rule, Part 2
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
Data structures lab
Data structures labData structures lab
Data structures lab
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
 
Power shell object
Power shell objectPower shell object
Power shell object
 
関数プログラミングことはじめ revival
関数プログラミングことはじめ revival関数プログラミングことはじめ revival
関数プログラミングことはじめ revival
 
Java binary subtraction
Java binary subtractionJava binary subtraction
Java binary subtraction
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
Algorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical FileAlgorithm Design and Analysis - Practical File
Algorithm Design and Analysis - Practical File
 
ゼロから始めるScala文法
ゼロから始めるScala文法ゼロから始めるScala文法
ゼロから始めるScala文法
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
 
C++ TUTORIAL 6
C++ TUTORIAL 6C++ TUTORIAL 6
C++ TUTORIAL 6
 
chap 2 Ex#1.1
chap 2 Ex#1.1chap 2 Ex#1.1
chap 2 Ex#1.1
 
Arrays matrix 2020 ab
Arrays matrix 2020 abArrays matrix 2020 ab
Arrays matrix 2020 ab
 
C++ TUTORIAL 7
C++ TUTORIAL 7C++ TUTORIAL 7
C++ TUTORIAL 7
 
Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in Python
 
Everything is composable
Everything is composableEverything is composable
Everything is composable
 

Similar to Promise

TDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação FuncionalTDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação Funcionaltdc-globalcode
 
Sorting programs
Sorting programsSorting programs
Sorting programsVarun Garg
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance HaskellJohan Tibell
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Mattersromanandreg
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdfkesav24
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingSaurabh Singh
 
Hitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingHitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingSergey Shishkin
 
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin WayTDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Waytdc-globalcode
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
Grokking Monads in Scala
Grokking Monads in ScalaGrokking Monads in Scala
Grokking Monads in ScalaTim Dalton
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기진성 오
 
Kotlin for Android Developers - 2
Kotlin for Android Developers - 2Kotlin for Android Developers - 2
Kotlin for Android Developers - 2Mohamed Nabil, MSc.
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 

Similar to Promise (20)

Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
TDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação FuncionalTDC2016SP - Trilha Programação Funcional
TDC2016SP - Trilha Programação Funcional
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
Hitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingHitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional Programming
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin WayTDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
 
Monadologie
MonadologieMonadologie
Monadologie
 
Grokking Monads in Scala
Grokking Monads in ScalaGrokking Monads in Scala
Grokking Monads in Scala
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Kotlin for Android Developers - 2
Kotlin for Android Developers - 2Kotlin for Android Developers - 2
Kotlin for Android Developers - 2
 
Scala by Luc Duponcheel
Scala by Luc DuponcheelScala by Luc Duponcheel
Scala by Luc Duponcheel
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Sorting techniques
Sorting techniques Sorting techniques
Sorting techniques
 

Recently uploaded

PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book nowPARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book nowkapoorjyoti4444
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Falcon Invoice Discounting
 
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service AvailableNashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service Availablepr788182
 
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...ssuserf63bd7
 
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGpr788182
 
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in PakistanChallenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistanvineshkumarsajnani12
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel
 
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...meghakumariji156
 
Falcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon investment
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with CultureSeta Wicaksana
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPanhandleOilandGas
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwaitdaisycvs
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptxnandhinijagan9867
 
Putting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxPutting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxCynthia Clay
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityEric T. Tung
 
QSM Chap 10 Service Culture in Tourism and Hospitality Industry.pptx
QSM Chap 10 Service Culture in Tourism and Hospitality Industry.pptxQSM Chap 10 Service Culture in Tourism and Hospitality Industry.pptx
QSM Chap 10 Service Culture in Tourism and Hospitality Industry.pptxDitasDelaCruz
 
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan CytotecJual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan CytotecZurliaSoop
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfAdmir Softic
 
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGpr788182
 

Recently uploaded (20)

PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book nowPARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
 
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service AvailableNashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
 
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
 
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in PakistanChallenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
 
Falcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business Potential
 
Buy gmail accounts.pdf buy Old Gmail Accounts
Buy gmail accounts.pdf buy Old Gmail AccountsBuy gmail accounts.pdf buy Old Gmail Accounts
Buy gmail accounts.pdf buy Old Gmail Accounts
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation Final
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptx
 
Putting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxPutting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptx
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
QSM Chap 10 Service Culture in Tourism and Hospitality Industry.pptx
QSM Chap 10 Service Culture in Tourism and Hospitality Industry.pptxQSM Chap 10 Service Culture in Tourism and Hospitality Industry.pptx
QSM Chap 10 Service Culture in Tourism and Hospitality Industry.pptx
 
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan CytotecJual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 

Promise

  • 1. Promise make your python code faster by promising to behave yourself Ryan Kelly [email_address]
  • 2.
  • 5.
  • 6. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
  • 7. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total timeit: 83
  • 8. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
  • 9. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 l_items = items while i < len( l_items ): total += calculate( l_items[i] ) i += 1 return total
  • 10. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.invariant([“items”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
  • 11. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.invariant([“items”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total timeit: 83 73
  • 12. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
  • 13. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate( len=len ): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
  • 14. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.constant([“len”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
  • 15. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.constant([“len”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total timeit: 83 77.1
  • 16. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
  • 17. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): x = items[i] total += 3*x*x - 2*x + (1 / x) i += 1 return total
  • 18. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
  • 19. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.constant([“calculate”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
  • 20. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.constant([“calculate”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total timeit: 83 60.5
  • 21. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.invariant([“items”]) @promise.constant([“len”,“calculate”]) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
  • 22. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.sensible() def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total
  • 23. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total promise.sensible()(globals())
  • 24. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len( items ): total += calculate( items[i] ) i += 1 return total promise.sensible()(globals()) timeit: 83 56.5
  • 25. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): i = 0 total = 0 while i < len(items): total += calculate(items[i]) i += 1 return total
  • 26. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): return sum(calculate(i) for i in items)
  • 27. items = [random.randint(0,100) for _ in xrange(100)] def calculate(x): return 3*x*x - 2*x + (1 / x) def aggregate(): return sum(calculate(i) for i in items) timeit: 83 59
  • 28. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.sensible() def aggregate(): return sum(calculate(i) for i in items)
  • 29. items = [random.randint(0,100) for _ in xrange(100)] @promise.pure() def calculate(x): return 3*x*x - 2*x + (1 / x) @promise.sensible() def aggregate(): return sum([calculate(i) for i in items]) timeit: 83 42.6
  • 30.
  • 32. >>> a = 1 >>> def add_a(b): ... return a + b ... >>>
  • 33. >>> a = 1 >>> def add_a(b): ... return a + b ... >>> >>> >>> dis.dis(add_a) LOAD_GLOBAL 0 (a) LOAD_FAST 0 (b) BINARY_ADD RETURN_VALUE >>>
  • 34. >>> a = 1 >>> @promise.invariant([&quot;a&quot;]) ... def add_a(b): ... return a + b ... >>>
  • 35. >>> a = 1 >>> @promise.invariant([&quot;a&quot;]) ... def add_a(b): ... return a + b ... >>> >>> >>> dis.dis(add_a) LOAD_GLOBAL 0 (a) STORE_FAST 1 (_promise_var1_a) LOAD_FAST 1 (_promise_var1_a) LOAD_FAST 0 (b) BINARY_ADD RETURN_VALUE >>>
  • 36. >>> a = 1 >>> @promise.constant([&quot;a&quot;]) ... def add_a(b): ... return a + b ... >>>
  • 37. >>> a = 1 >>> @promise.constant([&quot;a&quot;]) ... def add_a(b): ... return a + b ... >>> >>> >>> dis.dis(add_a) LOAD_CONST 1 (1) LOAD_FAST 0 (b) BINARY_ADD
  • 38. >>> a = 1 >>> def calc(): ... return add_a(7) ... >>> def add_a(b): ... return a + b ... >>>
  • 39. >>> a = 1 >>> def calc(): ... return add_a(7) ... >>> def add_a(b): ... return a + b ... >>> >>> dis.dis(calc) LOAD_GLOBAL 0 (add_a) LOAD_CONST 1 (7) CALL_FUNCTION 1 RETURN_VALUE >>>
  • 40. >>> a = 1 >>> @promise.constant([&quot;add_a&quot;]) ... def calc(): ... return add_a(7) ... >>> @promise.pure() ... def add_a(b): ... return a + b ... >>>
  • 41. >>> a = 1 >>> @promise.constant([&quot;add_a&quot;]) ... def calc(): ... return add_a(7) ... >>> @promise.pure() ... def add_a(b): ... return a + b ... >>> >>> dis.dis(calc) LOAD_CONST 1 ( <function apply_deferred_promises> ) LOAD_CONST 2 (<function calc>) CALL_FUNCTION 1 POP_TOP LOAD_GLOBAL 0 (add_a) LOAD_CONST 3 (7) CALL_FUNCTION 1 RETURN_VALUE >>>
  • 42. >>> calc._promise_deferred [<promise.constant object at 0xb77a5b0c>] >>>
  • 43. >>> calc._promise_deferred [<promise.constant object at 0xb77a5b0c>] >>> >>> calc() 8 >>>
  • 44. >>> calc._promise_deferred [<promise.constant object at 0xb77a5b0c>] >>> >>> calc() 8 >>> >>> dis.dis(calc) LOAD_CONST 1 (7) STORE_FAST 0 (_promise_var3_b) LOAD_CONST 2 (1) LOAD_FAST 0 (_promise_var3_b) BINARY_ADD JUMP_ABSOLUTE 16 RETURN_VALUE >>>
  • 45.
  • 47. For fun! None of my production code is CPU-bound
  • 48.
  • 49.
  • 50. You probably don't need to optimise that
  • 51.
  • 52. You probably don't need to optimise that
  • 53. You probably need a better algorithm
  • 54.
  • 55. come fork me: http://github.com/rfk/promise/