Hi Andrzej,
I would partially disagree with you on that. I do believe not all methods from your “code” is called by reflection but rather your code as Method, which is slightly different.
When it comes to comparing Invoke Code VS For each activities, I believe that when dealing with consistently large collection (where the perf effectively matter), activities will have slightly lower perfs for what i have tested.
I guess it is due to the fact that on each iteration inside the “body”, wwf needs to pass through the activity context of each scope (ex: Body=Asign) for each instruction you provide, which implies executign some .Net Code in the back.
I have small benchmark bulding a datatable one column and 1000000 rows (yes that what you need to see a difference…)
I’m invoking those two tests in both approaches :
For Each r As DataRow In dt.Rows
r(0) = r(0).ToString.Trim
Next
For Each r As DataRow In dt.Rows
r(0) = Guid.NewGuid.ToString
r(0) = r(0).ToString.Replace("a","")
r(0) = r(0).ToString.Trim
r(0) = Guid.NewGuid.ToString
r(0) = r(0).ToString.Replace("a","")
r(0) = r(0).ToString.Trim
Next
Invoke Code Test1: 00:03
Invoke Code Test2: 00:06
For each Activity Test1: 00:03
For each Activity Test2: 00:17+
Same results between for each and for each row.
Finally i did a last test using a one statement comparison using a an expensive expression:
New System.Text.RegularExpressions.Regex("\d{2}").Replace(String.Join("",Enumerable.Repeat(dt.Rows(0)(0),500000)).Replace(dt.Rows(0)(0).ToString.First,"y").Replace("y","z").Replace("z","a").Replace("a","b"),"\d{2}")
i get the same result (5 secs) for both
If you get different results or omitted on my comparisons let me know.
Main.xaml (24.8 KB)
Cheers
My since apologize to the OP who just wanted a trim on its header and end up with weather with debate if you should rather use invoke code, linq or a for each to put a rocket into space…