Skip to content

Commit

Permalink
[SofaPython3] Fix the benchmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
damienmarchal committed Jul 10, 2019
1 parent f15a7ed commit 1cb9112
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 48 deletions.
9 changes: 2 additions & 7 deletions bindings/Sofa/tests/bench_datacontainer.py
@@ -1,21 +1,16 @@
# coding: utf8

import sys
import os
import numpy
import timeit
sys.path.append("./Sofa/package")
sys.path.append("./SofaRuntime/package")

import Sofa
import Sofa.Core
import SofaRuntime

SofaRuntime.importPlugin("SofaAllCommonComponents")

import numpy
rawcpy = numpy.zeros((1000000,3), dtype=numpy.float64)

root = Sofa.Node("root")
root = Sofa.Core.Node("root")
obj = root.createObject("MechanicalObject", name="test", position=rawcpy.tolist())

it=10
Expand Down
34 changes: 5 additions & 29 deletions bindings/Sofa/tests/bench_node.py
Expand Up @@ -7,49 +7,33 @@
sys.path.append("./Sofa/package")
sys.path.append("./SofaRuntime/package")

import Sofa
import Sofa.Core
import SofaRuntime

SofaRuntime.importPlugin("SofaAllCommonComponents")

it=1000

root = Sofa.Node("rootNode")
root = Sofa.Core.Node("rootNode")
c = []
for i in range(0,1000):
newchild = root.createChild("Damien"+str(i))
newchild = root.addChild("Child"+str(i))
c.append(newchild)

parented = root.createChild("parented")
parented = root.addChild("parented")
for child in root.children:
child.addChild(parented)


def oldIt():
c = []
for e in root.__old_getChildren():
c.append(e)

def newIt():
c = []
for e in root.children:
c.append(e)

def oldRange():
c = []
for e in range(len(root.__old_getChildren())):
c.append(root.__old_getChild(e))

def newRange():
c = []
for e in range(len(root.children)):
c.append(root.children[e])

def oldRangeF():
c = []
for e in range(len(root.children)):
c.append(root.__old_getChild(e))

def newRangeF():
c = []
d = root.children
Expand All @@ -64,19 +48,11 @@ def newRangeF():
"len(parented.parents)",
"root.children",
"root.children[50]",
"root.__old_getChild(50)",
"root.children[50]",
"root.__old_getChild(50)",
"len(root.children)",
"len(root.__old_getChildren())",
"list(root.children)",
"root.__old_getChildren()",
"oldIt()",
"newIt()",
"oldRange()",
"newRange()",
"oldRangeF()",
"newRangeF()"]
"newRangeF()"]

for c in code:
print(c, timeit.timeit(c, number=it, globals=globals()))
Expand Down
14 changes: 6 additions & 8 deletions bindings/Sofa/tests/benchmark.py
Expand Up @@ -6,7 +6,7 @@
sys.path.append("./Sofa/package")
sys.path.append("./SofaRuntime/package")

import Sofa
import Sofa.Core
import SofaRuntime

SofaRuntime.importPlugin("SofaAllCommonComponents")
Expand All @@ -16,7 +16,7 @@
slowcpy = numpy.zeros((1000000,3), dtype=numpy.float32)
aList = rawcpy.tolist()

root = Sofa.Node("root")
root = Sofa.Core.Node("root")
obj = root.createObject("MechanicalObject", name="test", position=aList)

obj.position = aList
Expand All @@ -31,7 +31,7 @@
it = 1000

def pattern1SofaPython():
l = obj.position.tolist()
l = obj.position.toList()
for i in range(0, len(l)):
l[i]=[l[i][0]+1.0,l[i][0]+2.0,l[i][0]+3.0]
obj.position = l
Expand All @@ -50,7 +50,7 @@ def pattern1bisSofaPython3():

def pattern2SofaPython():
global aList
l = obj.position.tolist()
l = obj.position.toList()
for i in range(0, len(l)):
l[i]=[l[i][0]+aList[i][0],l[i][1]+aList[i][1],l[i][2]+aList[i][2]]
obj.position = l
Expand All @@ -59,10 +59,8 @@ def pattern2SofaPython3():
global rawcpy
obj.position += rawcpy


print(timeit.timeit("obj.position.tolist()", number=it, globals=globals()))
print(timeit.timeit("obj.position.toList()", number=it, globals=globals()))
print(timeit.timeit("obj.position", number=it, globals=globals()))
#print(timeit.timeit("obj.position[0,0]", number=it, globals=globals()))
it = 10

print("pattern 1")
Expand All @@ -74,11 +72,11 @@ def pattern2SofaPython3():
print(timeit.timeit("pattern2SofaPython()", number=it, globals=globals()))
print(timeit.timeit("pattern2SofaPython3()", number=it, globals=globals()))


print("setattr")
print(timeit.timeit("obj.position=aList", number=it, globals=globals()))
print(timeit.timeit("obj.position=rawcpy", number=it, globals=globals()))
print(timeit.timeit("obj.position=slowcpy", number=it, globals=globals()))

print("lastmile")
print(timeit.timeit("d = obj.position.copy()", number=it, globals=globals()))
print(timeit.timeit("d1 = rawcpy.copy()", number=it, globals=globals()))
Expand Down
6 changes: 2 additions & 4 deletions bindings/Sofa/tests/dataaccess.py
Expand Up @@ -4,10 +4,8 @@
import os
import numpy
import timeit
sys.path.append("./Sofa/package")
sys.path.append("./SofaRuntime/package")

import Sofa
import Sofa.Core
import SofaRuntime

SofaRuntime.importPlugin("SofaAllCommonComponents")
Expand All @@ -23,7 +21,7 @@ def oldSofa(obj):
ones = numpy.ones((1000,3), dtype=numpy.float64)
aList = zeros.tolist()

root = Sofa.Node("root")
root = Sofa.Core.Node("root")
obj = root.createObject("MechanicalObject", name="test", position=aList)
print("A counter: ", obj.position.getCounter())
obj.position += ones
Expand Down

0 comments on commit 1cb9112

Please sign in to comment.