Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
cpython/Tools/stringbench/README at pythoncapi · pythoncapi/cpython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
pythoncapi
/
cpython
Public
forked from
python/cpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
pythoncapi
Breadcrumbs
cpython
/
Tools
/
stringbench
/
README
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
68 lines (49 loc) · 2.46 KB
pythoncapi
Breadcrumbs
cpython
/
Tools
/
stringbench
/
README
Copy path
Top
File metadata and controls
Code
Blame
68 lines (49 loc) · 2.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
stringbench is a set of performance tests comparing byte string
operations with unicode operations. The two string implementations
are loosely based on each other and sometimes the algorithm for one is
faster than the other.
These test set was started at the Need For Speed sprint in Reykjavik
to identify which string methods could be sped up quickly and to
identify obvious places for improvement.
Here is an example of a benchmark
@bench('"Andrew".startswith("A")', 'startswith single character', 1000)
def startswith_single(STR):
s1 = STR("Andrew")
s2 = STR("A")
s1_startswith = s1.startswith
for x in _RANGE_1000:
s1_startswith(s2)
The bench decorator takes three parameters. The first is a short
description of how the code works. In most cases this is Python code
snippet. It is not the code which is actually run because the real
code is hand-optimized to focus on the method being tested.
The second parameter is a group title. All benchmarks with the same
group title are listed together. This lets you compare different
implementations of the same algorithm, such as "t in s"
vs. "s.find(t)".
The last is a count. Each benchmark loops over the algorithm either
100 or 1000 times, depending on the algorithm performance. The output
time is the time per benchmark call so the reader needs a way to know
how to scale the performance.
These parameters become function attributes.
Here is an example of the output
========== count newlines
38.54 41.60 92.7 ...text.with.2000.newlines.count("\n") (*100)
========== early match, single character
1.14 1.18 96.8 ("A"*1000).find("A") (*1000)
0.44 0.41 105.6 "A" in "A"*1000 (*1000)
1.15 1.17 98.1 ("A"*1000).index("A") (*1000)
The first column is the run time in milliseconds for byte strings.
The second is the run time for unicode strings. The third is a
percentage; byte time / unicode time. It's the percentage by which
unicode is faster than byte strings.
The last column contains the code snippet and the repeat count for the
internal benchmark loop.
The times are computed with 'timeit.py' which repeats the test more
and more times until the total time takes over 0.2 seconds, returning
the best time for a single iteration.
The final line of the output is the cumulative time for byte and
unicode strings, and the overall performance of unicode relative to
bytes. For example
4079.83 5432.25 75.1 TOTAL
However, this has no meaning as it evenly weights every test.
You can’t perform that action at this time.