Created
October 25, 2018 07:17
-
-
Save nrtkbb/2d49bd6c271a410fedf83820acaa2b50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import izip | |
from datetime import datetime | |
from maya import cmds | |
def slow_version(uvs): | |
a = ['meshName.uvst[0].uvsp[*]'] | |
a_append = a.append | |
for u, v in izip(uvs[0], uvs[1]): | |
a_append(u) | |
a_append(v) | |
# a data for "cmds.setAttr(*a, type='float2')" | |
def fast_version(uvs): | |
us, vs = uvs | |
s_len = len(us) | |
a = ['meshName.uvst[0].uvsp[*]'] + ([0] * (s_len * 2)) | |
def ud(i, u): | |
a[i*2+1] = u | |
def vd(i, v): | |
a[i*2+2] = v | |
(ud(i, u) for i, u in enumerate(us)) | |
(vd(i, v) for i, v in enumerate(vs)) | |
# a data for "cmds.setAttr(*a, type='float2')" | |
# Test data, Like a maya.api.OpenMaya.MFnMesh.getUVs return value. | |
uvs = [[0] * 100000000, [1] * 100000000] | |
start = datetime.now() | |
slow_version(uvs) | |
# My machine's output about 16 sec. | |
print('slow_version', str(datetime.now() - start)) | |
start = datetime.now() | |
fast_version(uvs) | |
# My machine's output about 3 sec. | |
print('fast_version', str(datetime.now() - start)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment