Skip to content

Instantly share code, notes, and snippets.

@Ryochan7
Created June 6, 2017 17:33
Show Gist options
  • Select an option

  • Save Ryochan7/0ac415934c06d4c868717f1502aa06fd to your computer and use it in GitHub Desktop.

Select an option

Save Ryochan7/0ac415934c06d4c868717f1502aa06fd to your computer and use it in GitHub Desktop.
Test smooth modifier routine
import math
from collections import deque
smoothtest = deque([ 0.0 ] * 8, maxlen=8)
weights = [ 0.75 ** x for x in reversed(xrange(8)) ]
weights2 = [ 0.75 ** x for x in xrange(8) ]
w_sum = sum(weights)
result = 0
def testkozec():
global smoothtest
global result
smoothtest.append(10000)
smoothtest.append(20000)
tempSum = sum(( smoothtest[i] * weights[i] for i in xrange(8) ))
result = tempSum / w_sum
return result
def testold():
global smoothtest
global result
smoothtest.appendleft(10000)
smoothtest.appendleft(20000)
tempSum2 = 0.0
currentWeight = 1.0
finalWeight = 0.0
for entry in smoothtest:
tempSum2 += entry * currentWeight
finalWeight += currentWeight
currentWeight *= 0.75
result = int(tempSum2 / finalWeight)
return result
if __name__ == "__main__":
import timeit
from time import time as t
"""st = t()
for i in xrange(1000000):
testold()
et = t()
print(et - st)
"""
print(timeit.timeit("testkozec()", setup="from __main__ import testkozec"))
print(result)
print(smoothtest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment