Created
June 6, 2017 17:33
-
-
Save Ryochan7/0ac415934c06d4c868717f1502aa06fd to your computer and use it in GitHub Desktop.
Test smooth modifier routine
This file contains hidden or 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
| 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