Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
a0d67e2f
Commit
a0d67e2f
authored
Apr 12, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a simple benchmark for f-strings
parent
a9d2637a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
Demos/benchmarks/fstrings.py
Demos/benchmarks/fstrings.py
+57
-0
No files found.
Demos/benchmarks/fstrings.py
0 → 100644
View file @
a0d67e2f
# coding=utf-8
# NOTE: requires Python 3.6 or later if not compiled with Cython
from
time
import
time
import
cython
@
cython
.
locals
(
x
=
int
,
n
=
int
)
def
run
():
t0
=
time
()
f
=
1.0
x
=
2
n
=
5
s
=
'abc'
u
=
u'üöä'
for
i
in
range
(
100
):
f"
{
n
}
oo
{
n
*
10
}{
f
:.
2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}
"
f"
{
n
}
oo
{
n
*
10
}{
f
:.
2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}
"
f"
{
n
}
oo
{
n
*
10
}{
f
:.
2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}
"
f"
{
n
}
oo
{
n
*
10
}{
f
:.
2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}
"
f"
{
n
}
oo
{
n
*
10
}{
f
:.
2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}
"
f"
{
n
}
oo
{
n
*
10
}{
f
:.
2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}
"
f"
{
n
}
oo
{
n
*
10
}{
f
:.
2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}
"
f"
{
n
}
oo
{
n
*
10
}{
f
:.
2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}
"
f"
{
n
}
oo
{
n
*
10
}{
f
:.
2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}
"
f"
{
n
}
oo
{
n
*
10
}{
f
:.
2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}
"
f"
{
n
}
oo
{
n
*
10
}{
f
:
3.2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}{
s
}
"
f"
{
n
}
oo
{
n
*
10
}{
f
:
5.2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}{
u
}
"
f"
{
n
}
oo
{
n
*
10
}{
f
:
2.2
}
--
{
n
:
2
}{
n
:
5
}
oo
{
i
}{
s
}
xx
{
u
}
"
tk
=
time
()
return
tk
-
t0
def
main
(
n
):
run
()
# warmup
times
=
[]
for
i
in
range
(
n
):
times
.
append
(
run
())
return
times
if
__name__
==
"__main__"
:
import
optparse
import
util
parser
=
optparse
.
OptionParser
(
usage
=
"%prog [options]"
,
description
=
"Test the performance of fstring literal formatting"
)
util
.
add_standard_options_to
(
parser
)
options
,
args
=
parser
.
parse_args
()
util
.
run_benchmark
(
options
,
options
.
num_runs
,
main
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment