SlideShare une entreprise Scribd logo
1  sur  13
Télécharger pour lire hors ligne
Da persistência de idéias ruins




                                  1
O aluno
def palindromo(s):
    for i in range(len(s)//2):
        if s[i] != s[-(i+1)]:
            return False


    return True



                                 2
O pythonista
def palindromo(s):
    return all([ s[i] == s[-(i+1)]
                 for i in range(len(s)//2)])




                                               3
O pythonista mais esperto
def palindromo(s):
    return all(( s[i] == s[-(i+1)]
                 for i in range(len(s)//2)))




                                               4
Aprendeu Lisp (ou Ruby)
def palindromo(s):
   return all(map(lambda t: t[0] == t[1],
                     [ (s[i], s[-(i+1)])
                       for i in range(len(s)//2)]))




                                                      5
Aprendeu Erlang (ou Haskell, ou Scheme)
def palindromo(s):
    if len(s) <= 1:
        return True
    elif s[0] == s[-1]:
        return palindromo(s[1:-1])
    else:
        return False

                                           6
Tem pressa (e Python 3)
from concurrent.futures.thread import ThreadPoolExecutor


def palindromo(s):
    with ThreadPoolExecutor(16) as executor:
        return all(executor.map(
                lambda t: t[0] == t[1],
                [ (s[i], s[-(i+1)])
                     for i in range(len(s)//2)]))


                                                           7
Tem pressa (e aprendeu sobre o GIL)
from concurrent.futures.process import ProcessPoolExecutor


def iguais(t):
    return t[0] == t[1]


def palindromo(s):
    with ProcessPoolExecutor() as executor:
        return all(executor.map(
                 iguais,
                 [ (s[i], s[-(i+1)])
                     for i in range(len(s)//2)]))
                                                             8
Gosta de poesia
def palindromo(s):
    return s[::-1] == s




                                9
Gosta de poesia (e de matemática)
def palindromo(s):
    return s[:len(s)//2:-1] == s[:len(s)//2]




                                               10
Recapitulando
●   Aluno
●   Pythonistas
●   Lambdista
●   Funcional
●   Threadista
●   Processista
●   Poetas

                                  11
Análise (pior caso)
1.00E+00




1.00E-01



                                                           aluno
1.00E-02
                                                           pythonista
                                                           pythonista esperto
                                                           lambdista
1.00E-03                                                   funcional
                                                           threadista
                                                           processista
                                                           poeta
1.00E-04                                                   poeta esperto




1.00E-05




1.00E-06
           10   100      1000   10000   100000   1000000


                                                                                12
http://about.me/rbanffy




                          13

Contenu connexe

Similaire à Da persistência de idéias ruins

Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101
Ankur Gupta
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
priestmanmable
 

Similaire à Da persistência de idéias ruins (20)

A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
SFSCON23 - Emily Bourne Yaman Güçlü - Pyccel write Python code, get Fortran ...
SFSCON23 - Emily Bourne Yaman Güçlü - Pyccel  write Python code, get Fortran ...SFSCON23 - Emily Bourne Yaman Güçlü - Pyccel  write Python code, get Fortran ...
SFSCON23 - Emily Bourne Yaman Güçlü - Pyccel write Python code, get Fortran ...
 
Hands on lua
Hands on luaHands on lua
Hands on lua
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
 
Programming Homework Help
Programming Homework Help Programming Homework Help
Programming Homework Help
 
C Programming Introduction
C Programming IntroductionC Programming Introduction
C Programming Introduction
 
matlab-python-xref.pdf
matlab-python-xref.pdfmatlab-python-xref.pdf
matlab-python-xref.pdf
 
Glowworm Swarm Optimisation
Glowworm Swarm OptimisationGlowworm Swarm Optimisation
Glowworm Swarm Optimisation
 
Ry pyconjp2015 turtle
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtle
 
ALFRED - www2013
ALFRED - www2013 ALFRED - www2013
ALFRED - www2013
 
The Little Register Allocator
The Little Register AllocatorThe Little Register Allocator
The Little Register Allocator
 
Seminar on MATLAB
Seminar on MATLABSeminar on MATLAB
Seminar on MATLAB
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101
 
Matlab python-
Matlab python-Matlab python-
Matlab python-
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
 
Scala
ScalaScala
Scala
 

Plus de Ricardo Bánffy

Faça seu próprio servidor pirata com OpenVZ
Faça seu próprio servidor pirata com OpenVZFaça seu próprio servidor pirata com OpenVZ
Faça seu próprio servidor pirata com OpenVZ
Ricardo Bánffy
 

Plus de Ricardo Bánffy (15)

Continuous testing of a terminal font
Continuous testing of a terminal fontContinuous testing of a terminal font
Continuous testing of a terminal font
 
Monitoring and automation
Monitoring and automationMonitoring and automation
Monitoring and automation
 
Measure everything you can
Measure everything you canMeasure everything you can
Measure everything you can
 
Lessons learned after 190M lessons served
Lessons learned after 190M lessons servedLessons learned after 190M lessons served
Lessons learned after 190M lessons served
 
Anti-patterns
Anti-patternsAnti-patterns
Anti-patterns
 
TDD with Python and App Engine
TDD with Python and App EngineTDD with Python and App Engine
TDD with Python and App Engine
 
TDD com Python e App Engine
TDD com Python e App EngineTDD com Python e App Engine
TDD com Python e App Engine
 
Boredom comes to_those_who_wait
Boredom comes to_those_who_waitBoredom comes to_those_who_wait
Boredom comes to_those_who_wait
 
Quem espera sempre cansa
Quem espera sempre cansaQuem espera sempre cansa
Quem espera sempre cansa
 
Zope
ZopeZope
Zope
 
Extreme Programming
Extreme ProgrammingExtreme Programming
Extreme Programming
 
Django para infográficos
Django para infográficosDjango para infográficos
Django para infográficos
 
Faça seu próprio servidor pirata com OpenVZ
Faça seu próprio servidor pirata com OpenVZFaça seu próprio servidor pirata com OpenVZ
Faça seu próprio servidor pirata com OpenVZ
 
CVS
CVSCVS
CVS
 
Ganhando dinheiro com software livre
Ganhando dinheiro com software livreGanhando dinheiro com software livre
Ganhando dinheiro com software livre
 

Da persistência de idéias ruins

  • 1. Da persistência de idéias ruins 1
  • 2. O aluno def palindromo(s): for i in range(len(s)//2): if s[i] != s[-(i+1)]: return False return True 2
  • 3. O pythonista def palindromo(s): return all([ s[i] == s[-(i+1)] for i in range(len(s)//2)]) 3
  • 4. O pythonista mais esperto def palindromo(s): return all(( s[i] == s[-(i+1)] for i in range(len(s)//2))) 4
  • 5. Aprendeu Lisp (ou Ruby) def palindromo(s): return all(map(lambda t: t[0] == t[1], [ (s[i], s[-(i+1)]) for i in range(len(s)//2)])) 5
  • 6. Aprendeu Erlang (ou Haskell, ou Scheme) def palindromo(s): if len(s) <= 1: return True elif s[0] == s[-1]: return palindromo(s[1:-1]) else: return False 6
  • 7. Tem pressa (e Python 3) from concurrent.futures.thread import ThreadPoolExecutor def palindromo(s): with ThreadPoolExecutor(16) as executor: return all(executor.map( lambda t: t[0] == t[1], [ (s[i], s[-(i+1)]) for i in range(len(s)//2)])) 7
  • 8. Tem pressa (e aprendeu sobre o GIL) from concurrent.futures.process import ProcessPoolExecutor def iguais(t): return t[0] == t[1] def palindromo(s): with ProcessPoolExecutor() as executor: return all(executor.map( iguais, [ (s[i], s[-(i+1)]) for i in range(len(s)//2)])) 8
  • 9. Gosta de poesia def palindromo(s): return s[::-1] == s 9
  • 10. Gosta de poesia (e de matemática) def palindromo(s): return s[:len(s)//2:-1] == s[:len(s)//2] 10
  • 11. Recapitulando ● Aluno ● Pythonistas ● Lambdista ● Funcional ● Threadista ● Processista ● Poetas 11
  • 12. Análise (pior caso) 1.00E+00 1.00E-01 aluno 1.00E-02 pythonista pythonista esperto lambdista 1.00E-03 funcional threadista processista poeta 1.00E-04 poeta esperto 1.00E-05 1.00E-06 10 100 1000 10000 100000 1000000 12