Проблема этого кода в том, что мы очень много раз вызываем функцию int.
Далее я нашел похожий вопрос/ответ на SO: https://stackoverflow.com/questions/12784192/is-there-a-faster-way-to-get-input-in-python.
В том же ответе на SO я нашел интересный трюк, который сильно ускоряет работу с цифрами, при условии, что мы работаем c ascii от 0 до 9.
Итак вместо того, чтобы вызывать функцию int, давайте попробуем вызывать более быструю функцию ord со сдвигом 48,
что позволит нам найти искомое число из строки.
Serverless is new trend in software development. It’s confusing many developers
around the world, let’s try to find origins of term “Serverless”.
First time Ken Fromm in 2012 use this term in his article.
(Ken added a bit of clarification in the comments to give credit where
credit is due.)
Later Badri Janakiraman mentioned that he also heard about usage of the term in 2012 in context
of Continuous Integration. For example Travis CI, where you can delegate
Continuous Integration and testing of your project to Travis CI.
Later in 2014 Amazon Web Services announced a new service Lambda, a stateless
event-driven compute service for dynamic applications that doesn’t require
provisioning of any compute infrastructure. As a result in 2015 we see lot’s
usage of term serverless.
In October 2015 there was a talk at Amazon’s re:Invent
conference titled “The Serverless Company using AWS Lambda”,
referring to PlayOn! Sports, where we can see real production usage of
AWS Lambda and Serverless architecture.
Let’s try to define term “Serverless”. Besides another trends in software
development, there is no one definition of this term.
Serverless is delegating hardware or infrastructure to third parties or vendors.
Serverless describes applications that depend on services ‘in the cloud’
to manage server-side logic and state. For example we have ‘rich client’
and we want to use the vast ecosystem of cloud accessible databases
(like Parse, Firebase), authentication services (Auth0, AWS Cognito), etc.
These types of services have been previously described as
‘(Mobile) Backend as a Service’, and I’ll be using ‘BaaS’ as a shorthand
in the rest of this article.
Wikipidea said, that Serverless is applications where some amount of
server-side logic is still written by the application developer but unlike
traditional architectures is run in stateless compute containers that are
event-triggered, ephemeral (may only last for one invocation), and fully
managed by a 3rd party. (Thanks to ThoughtWorks for their definition in their
most recent Tech Radar.)
One way to think of this is ‘Functions as a service / FaaS’ . AWS Lambda
is one of the most popular implementations of FaaS at present, but there
are others. I’ll be using ‘FaaS’ as a shorthand for this meaning of
Serverless throughout the rest of this article.
Serverless applications in Python sounds, strange isn’t? In this talk
I’ll explain how to build not only crop images or select data from DynamoDB,
but build real application, what kind of troubles are we should expect,
how to make decision is your task fit into serverless architecture in Python
or may be you should use, general approach. How fast serverless applications
written in Python, and more important how to scale it.
$ python3 fibonacci_generator.py # On my MacBook Pro (Mid 2015) 2.5 GHz Intel Core i7, 16 GB 1600 MHz DDR3
About timeit instead of conclusion.
Also keep in mind:
Note By default, timeit() temporarily turns off garbage collection during the timing. The advantage of this approach is that it makes independent timings more comparable. This disadvantage is that GC may be an important component of the performance of the function being measured. If so, GC can be re-enabled as the first statement in the setup string.
“Mathematics reveals its secrets only to those who approach it with pure love, for its own beauty.”
Why do you need to copy a Python strings? It’s interesting question,
because Python string is immutable. Also any tries of copy will returns
the original string. Python tries to keep just the one copy,
as that makes dictionary lookups faster.
May be use slice?
Python 3.5.2 (default, Sep 15 2016, 07:38:42)[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license"for more information.
>>> b= a[:]
>>> b= a[:]
>>> id(a), id(b)(4400931648, 4400931648)
Add empty string? No!
>>> a = 'python'
>>> b = a + ''
Or use str function?
>>> a = 'python'
>>> b =str(a)
What is the best full text search engine for python?
Nowadays we can see lot’s of benchmarks and performance tests of different
web frameworks and Python tools. Regarding to search engines, it’s difficult
to find useful information especially benchmarks or comparing between
different search engines. It’s difficult to manage what search engine you
should select for instance, ElasticSearch, Postgres Full Text Search or may
be Sphinx or Whoosh. You face a difficult choice, that’s why I am pleased to
share with you my acquired experience and benchmarks and focus on how to
compare full text search engines for Python.
You can watch my video from EuroPython 2016 in Bilbao.
Social phenomena is coming. We have lot’s of social applications that we
are using every day, let’s say Facebook, twitter, instagram.
Lot’s of such kind apps based on social graph and graph theory.
I would like to share my knowledge and expertise about how to work with graphs
and build large social graph as engine for Social network using python
and Graph databases. We’ll compare SQL and NoSQL approaches for friends relationships.
Nowadays we can see lot’s of benchmarks and performance tests of
different web frameworks and Python tools. Regarding to search engines,
it’s difficult to find useful information especially benchmarks or comparing
between different search engines. It’s difficult to manage what search
engine you should select for instance, ElasticSearch, Postgres Full Text
Search or may be Sphinx or Whoosh. You face a difficult choice, that’s why
I am pleased to share with you my acquired experience and benchmarks
and focus on how to compare full text search engines for Python.