Skip to content

Commit

Permalink
Merge pull request #66 from OmarWagih1/added_polygon_benchmark
Browse files Browse the repository at this point in the history
Added Polygon benchmark
  • Loading branch information
asmeurer authored Mar 18, 2020
2 parents 0dbe7a6 + 34b1680 commit 928b681
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions benchmarks/polygon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from __future__ import print_function, division
from distutils.version import LooseVersion, StrictVersion
from sympy import Rational
import sympy
from sympy.geometry import (Line, Point,
Polygon)
from random import randint
listOfPolygons = [Polygon(Point(0+w,0+w),
Point(3+w,0+w),
Point(3+w,3+w),
Point(0+w,3+w)) for w in range(10)]
cutListOfPolygons = [Polygon((-1, -1), (1, Rational(5, 2)), (2, 1), (3, Rational(5, 2)), (4, 2), (5, 3), (-1, 3)) for w in range(10)]
cutLines = [Line((0, 0), (Rational(9, 2), 3)) for w in range(10)]

class PolygonAttributes:
def time_create(self):
"Creating Polygon"
Polygon(Point(0, 0), Point(3, -1),Point(6, 0), Point(4, 5))

def time_area(self):
"Polygon.area for w in range(10)"
[listOfPolygons[w].area for w in range(10)]

def time_perimeter(self):
"Polygon.perimeter for w in range(10)"
[listOfPolygons[w].perimeter for w in range(10)]

def time_sides(self):
"Polygon.sides for w in range(10)"
[listOfPolygons[w].sides for w in range(10)]

def time_centroid(self):
"Polygon.centroid for w in range(10)"
[listOfPolygons[w].centroid for w in range(10)]

class PolygonIsConvex:
def time_bench01(self):
"Polygon.is_convex() for w in range(10)"
[listOfPolygons[w].is_convex() for w in range(10)]

class PolygonEnclosesPoint:
def time_bench01(self,Point2=Point(randint(0,10),randint(0,10))):
"Polygon.encloses_point for w in range(10)"
[listOfPolygons[w].encloses_point(Point2) for w in range(10)]

class PolygonArbitraryPoint:
def time_bench01(self):
"Polygon.arbitrary_point for w in range(10)"
[listOfPolygons[w].arbitrary_point() for w in range(10)]

class PolygonDistance:
def time_bench01(self):
"Polygon.distance() for w in range(10)"
[listOfPolygons[w].distance(Point(randint(0,10),randint(0,10))) for w in range(10)]

class PolygonSecondMoment:
def setup(self):
if StrictVersion(sympy.__version__) < StrictVersion("1.3.0"):
raise NotImplementedError
def time_bench01(self):
"Polygon.second_moment_of_area() for w in range(10)"
[listOfPolygons[w].second_moment_of_area() for w in range(10)]

class PolygonFirstMoment:
def setup(self):
if StrictVersion(sympy.__version__) < StrictVersion("1.5.0"):
raise NotImplementedError
def time_bench01(self):
"Polygon.first_moment_of_area for w in range(10)"
[listOfPolygons[w].first_moment_of_area() for w in range(10)]

class PolygonPolarSecondMoment:
def setup(self):
if StrictVersion(sympy.__version__) < StrictVersion("1.5.0"):
raise NotImplementedError
def time_bench01(self):
"Polygon.polar_second_moment_of_area for w in range(10)"
[listOfPolygons[w].polar_second_moment_of_area() for w in range(10)]

class PolygonSectionModulus:
def setup(self):
if StrictVersion(sympy.__version__) < StrictVersion("1.5.0"):
raise NotImplementedError
def time_bench01(self):
"Polygon.section_modulus for w in range(10)"
[listOfPolygons[w].section_modulus() for w in range(10)]

class PolygonCutSection:
def setup(self):
if StrictVersion(sympy.__version__) < StrictVersion("1.5.0"):
raise NotImplementedError
def time_bench01(self):
"Polygon.cut_section for w in range(10)"
[cutListOfPolygons[w].cut_section(cutLines[w]) for w in range(10)]

0 comments on commit 928b681

Please sign in to comment.