Notifications
Clear all

[Closed] Why the mesh operation is much much faster than poly operations?

This is the code:


 (
 	o = $
 	st = timestamp()
 	local maxMatID = 0
 	
 	--	for Editable_Poly
 	local allFaces = getNumFaces o
 	for f in 1 to allFaces do
 	(
 		local matID = o.getFaceMaterial f
 		if matID > maxMatID do maxMatID = matID
 	)
 	--	for Editable_mesh
 -- 	local allFaces = getNumFaces o
 -- 	for f in 1 to allFaces do
 -- 	(
 -- 		matID = getFaceMatID o f
 -- 		if matID > maxMatID do maxMatID = matID
 -- 	)	
 	end = timestamp()
 	format "allFaces: %
" allFaces
 	format "maxMatID: %
" maxMatID
 	format "time: %
" ((end-st)/1000.0)
 )

and this is the result(tested on teapot with 4 TS modifiers, converted to Editable_Poly and Editable_Mesh.)

For Editable_Poly object:
allFaces: 129024
maxMatID: 13
time: 107.672

For Editable_Mesh object:
allFaces: 258048
maxMatID: 13
time: 0.812

0.812 vs 107.612 !!!

14 Replies

But…


(
	o = $
	st = timestamp()
	
	local elementsNum = 0
	--	Editable_poly
	local faceCount = polyOp.getNumFaces o
	local allFaces = #{1..faceCount}
	while not allFaces.isEmpty do
	(					
		--	get element
		elemFaces = polyOp.getElementsUsingFace o #{(allFaces as array)[1]}
		--	count the element
		elementsNum += 1									
		--	exclude faces of this element
		allFaces = allFaces - elemFaces
	)
	
	--	Editable_mesh
-- 	local faceCount = meshop.getNumFaces o
-- 	local allFaces = #{1..faceCount}
-- 	while not allFaces.isEmpty do
-- 	(					
-- 		--	get element
-- 		elemFaces = meshop.getElementsUsingFace o #{(allFaces as array)[1]}
-- 		--	count the element
-- 		elementsNum += 1									
-- 		--	exclude faces of this element
-- 		allFaces = allFaces - elemFaces
-- 	)	
	
	end = timestamp()
	format "faceCount: %
" faceCount
	format "elementsNum: %
" elementsNum
	format "time: %
" ((end-st)/1000.0)
)

The same teapot
For Editable_Poly:
faceCount: 129024
elementsNum: 4
time: 0.781

For Editable_Mesh:
faceCount: 258048
elementsNum: 4
time: 4.453

0.781 vs. 4.453!!

Don’t use getFaceMaterial.
Use polyop.getFaceMatID.

Why is one faster then the other? No idea, but that’s how it is with Maxscript.

With polyop.getFaceMatID instead of getFaceMaterial:
Editable_Poly: time = 1.25 (not 107.6)

you are measuring the wrong things…
both getFaceMaterial and getFaceMatID methods are interface functions. when you call any interface function the time of execution is combined time of access to the function and actual execution.

test #1 (yours original)


 (
	 delete objects
	node = converttopoly (geosphere segments:50) -- 50000 polys
	 gc()
	t1 = timestamp()

	 for f=1 to node.numfaces do (node.getFaceMaterial f)
	 format "faces:% time:%
" node.numfaces ((timestamp()- t1 as float)/1000) 
 )

faces:50000 time:15.748

test #2 (pro ;))


(
	 delete objects
	node = converttopoly (geosphere segments:50) -- 50000 polys
	 gc()
	t1 = timestamp()

	getFaceMaterial = node.getFaceMaterial
	 for f=1 to node.numfaces do (getFaceMaterial f)
	 format "faces:% time:%
" node.numfaces ((timestamp()- t1 as float)/1000) 
 )

faces:50000 time:0.036

so you can see the difference. all time of execution is spent for access!

now check the polyop interface:
#1


 (
 	delete objects
 	node = converttopoly (geosphere segments:50) -- 50000 polys
 	gc()
 	t1 = timestamp()
 
 	for f=1 to node.numfaces do (polyop.getFaceMatID node f)
 	format "faces:% time:%
" node.numfaces ((timestamp()- t1 as float)/1000) 
 )
 

faces:50000 time:0.056

#2:


 (
 	delete objects
 	node = converttopoly (geosphere segments:50) -- 50000 polys
 	gc()
 	t1 = timestamp()
 
 	getFaceMatID = polyop.getFaceMatID
 	for f=1 to node.numfaces do (getFaceMatID node f)
 	format "faces:% time:%
" node.numfaces ((timestamp()- t1 as float)/1000) 
 )
 

faces:50000 time:0.032

access to polyop methods is much faster than to EditablePoly… the time of execution is almost the same. which is not surprising. both interfaces are sharing the same code.

also check the memory usage (leaking) for all four examples. that’s is very interesting too.
for many cases the memory issue is more important than speed.

Hi, denisT!
I’m using … predefining(i don’t know how to say in english) of polyOp operations in some of my scripts (this foe example)because I know that this will speed up performance, but did’n know that the diference is so big.
Thank you for showing me this tip. I will remember it.

One question – how to check how memory is used? Watching the Task Manager is not verry helpful.

if you want to know why the results are so different, i can answer.
because the developers are different. some is smart and accurate, another is lazy and negligent…
here is a result.

check the heapfree before and after:


 (
 	m1 = heapfree
 	... -- the test
 	(m1 - heapfree)
 )
 
Page 1 / 2