c# - Most efficent way to work with IEnumerable -
what efficient way traverse collection/ienumeration in c#. have list contains 1100 objects. 10 of objects, inturn contain 1000 subobjects (of same type). traversal list takes 5-6 seconds. here code:
foreach (parameter par in this.allparameters) //this.allparameters generic.list type { foreach (parameter subpar in par.wrappedsubparameters) { subpar.isselected = false; } par.isselected = false; }
is there way optimize code fast enough, not taking 5-6 seconds?
the loops, written, 1 of fastest options.
since in memory, , each write operation appears on separate instance (no synchronization), potentially parallelize gains:
parallel.foreach(this.allparameters, par => { foreach (parameter subpar in par.wrappedsubparameters) { subpar.isselected = false; } par.isselected = false; });
note i'm parallelizing outer loop (on purpose), should provide enough work items adequately use processing cores.
another potential issue - if isselected
properties bound control via data binding, ui potentially updating continually, explain slow update times. cause parallelization have no real effect, well, since bottle neck not these loops, rather ui binding.
you may want unbind/rebind control, or suspend updates on control until you're loop completed.
Comments
Post a Comment