I created a UDF to test (random selection) a population of 5 million theoretical records. Although I have not attempted to run this sample against the full 5 million, I have tested it against 50,000 and 150,000 records and noticed that my function will process 50,000 records in 70 seconds and 150,000 in 275 seconds. The results or the records selected are captured in an array. I included the basic building blocks of my function in the code section below so you can get an idea on how I structured the UDF. My concern is that the speed of the function is slowing down as more records are processed. I also noticed that my CPU usage for Alpha stays around 8.5% and the memory usage stays around 70 mb. If there is a way to utilize the full capacity of my CPU, I am open to suggestions. If there is a more efficient method to design my UDF, I will appreciate any input. I did try to maximize the efficiency of my UDF through the following:
I realize I could break out my criteria check into its own independent process to reduce the loops but the combined process time may be the same. I was hoping someone would have a suggestion on the function as is before I go down this road. Could changing the loop method make a difference? It appears Alpha is only using 1 of my 12 processing cores. Is there a way to increase this?
- The function type is V
- The function does not make any calls to any other global UDF
- While minimizing the use of functions, any necessary functions are embedded in my UDF.
- I minimized the use of variables unless necessary.
Code:
myFunction as V () dim sample[] as P dim some_other_vars for i = 1 to 5000000[INDENT]ranNum = my_Embedded_RanNum_Generator() if ranNum < .01 then[/INDENT][INDENT=2] dim a as L[/INDENT][INDENT=2]a = meets_criteria_check() if a then[/INDENT][INDENT=3]sample[].number = i sample[..].other_stuff = other stuff[/INDENT][INDENT=2]end if[/INDENT][INDENT]end if[/INDENT] next i file.From_property("test/test.txt", sample) End Function
Comment