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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
0cbd5d47
Commit
0cbd5d47
authored
Jun 17, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved the first example of "early binding for speed" in the examples directory for testing.
parent
46b39552
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
16 deletions
+20
-16
docs/examples/userguide/early_binding_for_speed/rectangle.pyx
.../examples/userguide/early_binding_for_speed/rectangle.pyx
+19
-0
docs/src/userguide/early_binding_for_speed.rst
docs/src/userguide/early_binding_for_speed.rst
+1
-16
No files found.
docs/examples/userguide/early_binding_for_speed/rectangle.pyx
0 → 100644
View file @
0cbd5d47
cdef
class
Rectangle
:
cdef
int
x0
,
y0
cdef
int
x1
,
y1
def
__init__
(
self
,
int
x0
,
int
y0
,
int
x1
,
int
y1
):
self
.
x0
=
x0
self
.
y0
=
y0
self
.
x1
=
x1
self
.
y1
=
y1
def
area
(
self
):
area
=
(
self
.
x1
-
self
.
x0
)
*
(
self
.
y1
-
self
.
y0
)
if
area
<
0
:
area
=
-
area
return
area
def
rectArea
(
x0
,
y0
,
x1
,
y1
):
rect
=
Rectangle
(
x0
,
y0
,
x1
,
y1
)
return
rect
.
area
()
docs/src/userguide/early_binding_for_speed.rst
View file @
0cbd5d47
...
...
@@ -22,22 +22,7 @@ use of 'early binding' programming techniques.
For example, consider the following (silly) code example:
.. sourcecode:: cython
cdef class Rectangle:
cdef int x0, y0
cdef int x1, y1
def __init__(self, int x0, int y0, int x1, int y1):
self.x0 = x0; self.y0 = y0; self.x1 = x1; self.y1 = y1
def area(self):
area = (self.x1 - self.x0) * (self.y1 - self.y0)
if area < 0:
area = -area
return area
def rectArea(x0, y0, x1, y1):
rect = Rectangle(x0, y0, x1, y1)
return rect.area()
.. literalinclude:: ../../examples/userguide/early_binding_for_speed/rectangle.pyx
In the :func:`rectArea` method, the call to :meth:`rect.area` and the
:meth:`.area` method contain a lot of Python overhead.
...
...
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