Grasshopper

algorithmic modeling for Rhino

Hi all,

I m trying for the first time to execute a command using multiple threads. For time comparison purposes I am running the same command as single-threaded, recording the computing time using "time" module. Strangely enough, the multi-threaded one runs remarkably slower, whereas the order of the printed results is senseless. Does anybody have experience on how to make it work properly? Already checked the post here.

import System.Threading.Tasks as tasks
import time, math

#single-threaded

start = time.time()
for i in range(1,501):
print i
end = time.time()
print "single = ", end-start

#multi-threaded

iterations = 500
def get_i(i):
print i
start = time.time()
tasks.Parallel.ForEach(xrange(iterations), get_i)
end = time.time()
print "multi = ", end-start

1. As (a) the values are printed in random order and (b) the computing time is high, are there any clues what i am doing wrong?

2. Is there a more accurate way to compute the required time for a command or a chunk of a script?

Thanks and best,

jnm

Views: 864

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service