speed-up of a function
- To: mathgroup at smc.vnet.net
- Subject: [mg45072] speed-up of a function
- From: Kastens at Hamburg.BAW.DE (Marko Kastens)
- Date: Tue, 16 Dec 2003 06:20:56 -0500 (EST)
- Organization: BAW-AK, Hamburg-Rissen, Germany
- Sender: owner-wri-mathgroup at wolfram.com
Hi! I have something like this: (two lists(sublistTNW1 and sublistTNW2)), containing both time (Integer) and a value (Real)). The following function pick-up the next dataset(time,value) out of sublistTNW2 after the given time (sublistTNW1[[i,1]]). NextEvent[t_, list_] := Select[list, (#[[1]] >= t) &, 1] For[i = 1, i < 500, { NextEvent[sublistTNW1[[i, 1]], sublistTNW2] }; i++] Calling the function in the for-loop very often (f.ex 500 times or more) is indeed very slowly. Trying to compile the function testfunc = Compile[{{t, _Integer}, {list, _Real, 2}}, Select[list, (#[[1]] >= t) &, 1]] takes no effect in speed-up. Perhabs I've used the compile-Function not correctly? How can I use lists with different data types in compile? {list, _Real, 2} (s.a.) is not exactly right, because the list is in the format {_Integer,_Real}. Thanks for any suggestions, marko