AddRange ObservableCollection Issue - vb.net

Hi I'm using this link to implement Fastest Observable Collection
Best performance for ObservableCollection.AddRange
ObservableCollection Doesn't support AddRange method, so I get notified for each item added, besides what about INotifyCollectionChanging?
But on Calling AddRange() or ReplaceRange() methods multiple times, the performance gets slow, for example
AddRange() executed first time in 0.5 sec.
AddRange() executed 2nd Time in 1 sec.
AddRange() executed 3rd Time in 2.5 sec.
And it keep taking more time to execute methods even with same data.
For Better understanding, here is a code
For Each serie In SeriesList
serie.SeriesDisplayName = "New Series " + newSeriesCounter.ToString()
If newSeriesCounter = 1 Then
serie.Items(1).Number = 500
End If
newSeriesCounter += 1
Next
Series.Clear()
Series.AddRange(SeriesList)

Related

Repast: check execution time for each method

My model is gradually slower down to an unacceptable speed(i.e. from 200 ticks per second to several seconds for one tick). I'd like to understand what the causes to this problem. What is a simplest way to check which part of the model is increasingly consuming the time? I tried used some other java profiler before but it's not good and difficault to understand.
A Java profiler like YourKit is the best way approach since it will provide the code "hots pots" in terms of the execution times for each class method. Alternatively, you can insert a few timing functions in parts of your model that you suspect contribute to most of the execution time, for example:
long start = System.nanoTime();
// some model code here
long end= System.nanoTime();
System.println("Step A time in seconds: " + (end - start)/1E9);

Parallel.For and/or Parallel.ForEach not spawning new threads

For the sake of completeness, I've searched and read other articles here, such as:
Parallel.ForEach not spinning up new threads
but they don't seem to address my case, so off we go:
I have a Parallel.ForEach of an array structure, like so:
Dim opts As New ParallelOptions
opts.MaxDegreeOfParallelism = intThreads
Parallel.ForEach(udtExecPlan, opts,
Sub(udtStep)
Dim strItem As String = udtStep.strItem
Basically, for each item, I do some nested loops and end up calling a function with those loop assignments as parameters.
The function executes a series of intense calculations (which takes up most of the function's processing time) and records the results on an MSSQL table, and if some conditions are met, the function returns True, else False. If the result is True, then I simply Return from the parallel function Sub(udtStep) and another item from the array should continue. If the result is False, I simply go through another interation of the deepest nested loop, and so on, working towards the completion of the other outer loops, etc. So, in a nutshell, all nested loops are inside the main Parallel.ForEach loop, like so:
Parallel.ForEach(udtExecPlan, opts,
Sub(udtStep)
Dim strItem As String = udtStep.strItem
If Backend.Exists(strItem) Then Return
For intA As Integer = 1 To 5
For intB As Integer = 1 To 50
Dim booResult As Boolean = DoCalcAndDBStuff(strItem, intA, intB)
If booResult = True Then Return
Next intB
Next intA
End Sub)
It is important to notice that udtExecPlan has about 585 elements. Each item takes from 1 minute to several hours to complete.
Now, here's the problem:
Whether I do this:
Dim opts As New ParallelOptions
opts.MaxDegreeOfParallelism = intThreads
Parallel.ForEach(udtExecPlan, opts,
where intThreads is the core count, or whatever number I assign to it (tried 5, 8, 62, 600), or whether I simply omit the whole the ParallelOptions declaration and opts from the Parallel.ForEach statement, I notice it will spin up as many threads I have specified upto the total amount of cores (including HT cores) in my system. That is all fine and well.
For example, on an HP DL580G7 server with 32 cores / 64 HT cores and 128GB RAM, I can see 5, 8, 62 or 64 (using the 600 option) threads busy on the Task Manager, which is what I'd expect.
However, as the items on the array are processed, the threads on Task Manager "die off" (go from around 75% utilization to 0%) and are never spun up again, until only 1 thread is working. For example, if I set intThreads to 62 (or unlimited if I omitted the whole ParallelOptions declaration and opts from the Parallel.ForEach statement), I can see on the db table that 62 (or 64) items have been processed, but from then on, it just falls back to 1 thread and 1 item at a time.
I was expecting that a new thread would be spun up as soon as an item was done, as there are some 585 items to go through. It is almost as if 62 or 64 items are done in parallel and then on only 1 item until completion, which renders the whole server practically idling thereafter.
What am I missing?
I have tried some other different processes with a main Parallel.For loop (no other outer loop present, just as in this example) and get the same behaviour.
Why? Any thoughts welcome.
I am using VS.NET 2015 with .NET Framework 4.6.1, W2K8R2 fully patched.
Thanks!

How to get the latest value emited from observable

Suppose, i have a timer which emits one item after one second interval.
I want to subscribe to it and execute it for 10 seconds. After 10 seconds i unsubscribe from it and then i want to be able to have access to its last emmited value from some other part of the code.
Here is sample code:
#Test
fun testMeasuretime(){
val emitter = Observable.interval(1, TimeUnit.SECONDS)
.doOnNext{t: Long? -> Log.v("emitter", t.toString())}
val disposable = emitter.subscribe()
Thread.sleep(10000)
disposable.dispose()
Thread.sleep(5000)
//get the last emited value
Thread.sleep(5000)
}
Is there a way to get the last emited value from ohter part of the code?
I want to use this solution to just measure time execution of some task.
You can get the last value by either using doOnNext() to set the value of a class field, or inserting a BehaviorSubject in the path.
However, I don't think your code is actually measuring the CPU time of execution of the task. Instead, it is capturing the start and end points of processing on possibly an unrelated thread. So, the best you can get is the wall-clock time.
A better approach is something like (written in Java, since I don't know Kotlin):
long start = System.nanoTime();
performTaskOnThisThread();
long end = System.nanoTime();
long durationInNanoSeconds = end - start;

Static timed loop in objective-c cocos2d?

Looking for some ideas on how to implement this, don't necessarily need the exact code.
Let's say I have a game where the player's hit points are displayed in a label, say 100HP. When he takes damage, say 30 damage, I want that label to count down from 99, 98 , 97 ... 70. It should take 2 seconds to perform the countdown whether you take 30 damage or 3000 damage.
I'm wondering what's the most efficient way to get this loop to count down "smoothly" over 2 seconds no matter what the damage taken is.
I'd probably extend a CCLabelSomething to do that, embedding the desired behaviour. Suggest a fixed width font, otherwise nothing smooth will happen (visually). Figure out what is 'smooth for you', ie how many updates in the 2 second period. in the assumed 'setScore' public method, start a scheduled update cycle with appropriate delay. In the schedule callback, change the text of the label.
say 20 updates, ie 10 per seconds. Schedule with .1f delay between intervals. Upon setScore, compute the 'delta' per update (currentScore - newScore)/20. Decrement currentScore down to newScore by this delta. In the schedule callBack, stop your scheduled update if the displayed score is equal to the newScore.

(UIAElementArray) elements() is slow

It takes 4 sec to execute. Is it normal?
I'm developing a search method, that crawls trough the element tree, but in each iteration when I call an element's elements() method, it holds for 4 sec. Having 15 nodes in the tree, it takes a minute!
Any idea on how to find an element?
Use the methods on UIATarget to decrease the default timeout (5 seconds), for example pushTimeout(0.5).