Archive

Archive for May, 2018

Improving .NET #performance with Parallel.For

tuning-performance

If you ever have a bit of code that does this;

var strSoughtUrl = “”
for each url in urls
var blnFoundIt = MakeWebRequestAndFindSomething(url);
if (blnFoundIt)
{
strSoughtUrl = url
}
next

That is to say, loops through a list of Urls, makes a web request to each one, and then breaks when it finds whatever you were looking for –

Then you can greatly improve the speed of the code using Parellel.for to something like this;

var resultCollection = new ConcurrentBag<string>();
Parallel.For(0, urls.Count, (i,loopstate) =>
{
var url = urls[(int)i];
var blnFoundIt = MakeWebRequestAndFindSomething(url);
if (blnFoundIt)
{
resultCollection.Add(url);
loopstate.Stop();
}
});
var strSoughtUrl = resultCollection.ToArray().First()

I have seen this code speeding up from 22 seconds to 5 seconds when searching through about 100 urls, since most of the time spent requesting a url is waiting for another machine to send all it’s data.

This is yet another performance increase for the Car Registration API service! 🙂

Advertisement
Categories: Uncategorized

#OpenSource KBA & Natcode lookup App for iOS in #Swift

690x0w

This app allows German and Austrian users search for German KBA (“Kraftfahrt-Bundesamt”) codes, and Austrian NatCode (“Nationaler Code”) by searching by make and model, or by entering the code in the search box.

There is also an API that allows businesses to obtain this data automatically. If you are interested in the API, please visit our German or Austrian website at http://www.kbaapi.de or http://www.natcode.at

The source code for the app is available (minus the API Keys), at Github: https://github.com/infiniteloopltd/KBA-Natcode/ it’s written in Swift, and it’s the first app we’ve published that’s entirely written natively.

The App itself can be downloaded from iTunes here;

https://geo.itunes.apple.com/us/app/kba-und-natcode/id1378122352?mt=8&uo=4&at=1000l9tW

 

Categories: Uncategorized
%d bloggers like this: