Home > Uncategorized > C# classes update

C# classes update

This is a follow up of the previous post.

I owe an apology for the C# team. (See the updates.) There was an error in the test code. While deleting items randomly from my own ZSortedList, I always deleted the first item from the SortedList, which meant it had to move the whole array when freeing space at every step, making it slower. With the fixed code the performance of the two implementations are much closer to each other when working with relatively low number of items. At very low item numbers the SortedList even beats ZSortedList (not after update3), but above a given number the two lists perform similarly, but as it turns out ZSortedList is still faster.

UPDATE: SortedList never changes its capacity unless it’s told to, while I always free up unnecessary space on remove. Now that’s what I call cheating. :p

UPDATE2: My idea that having to search twice is slow was proven incorrect. Once I changed the code so my list also uses exception handling and creates a variable to insert with new, even if the position turns out to be taken, ZSortedList easily wins.

In conclusion I can say that the built in container types (or at least the SortedList) are not as bad as I first made them look like are even worse than I thought at first, and it is possible to make better ones when working with a large amount of data where speed is critical. You can even gain minutes or hours! But plain old arrays are still much faster.

Updated2 results:
random insertion and deletion: 1024 * 200

Test1: ZSortedList first checks for a position to insert a new item, but doesn’t create it unless the position is free.
ZSortedList: 47726ms (+5959ms)
SortedList: 40767ms

Test2: Using ZSortedList exactly like SortedList. Calling “Add” with a newly created object, and if the position is not free, handling the exception.
ZSortedList: 30014ms
SortedList: 40372ms (+10371ms !!)

UPDATE3:
After changing that even the binary search is done by my own code, ZSortedList finishes the 1024*200 items test in 16000ms, which is half of the previous record, and even that could beat the built in SortedList!

After measuring both the insertion and deletion times I realized that the way I aggressively freed up data slowed things down a lot, but it’s not impossible to improve the performance simply in C# code. I’m now curious how C++ classes would measure up here but I won’t be testing that in a while.

Advertisements
Categories: Uncategorized
  1. January 20, 2012 at 3:13 am

    Quero dizer neste comentário que decidi utilizar permanentemente a versão 7.1 do ZKanji, Já que ela foi a última com a opção de janelas individuais. Para isso, gostaria de saber se existe algum modo de as frases de exemplo serem utilizadas lá também, já que percebi que na versão 7.17 existe esse recurso e deixar o okurigana colorido também. Além disso gostaria de saber se existe alguma maneira de traduzir as frases de exemplo, pois as definições dos Kanjis e o dicionário podem ser traduzidas.

    Grato

    • January 20, 2012 at 1:27 pm

      Most recent versions come with example sentences, but I only upload new ones when the dictionary data also changes. v0.71 uses the data from v0.7 so you need to get zexamplesv07.zip from here:
      http://sourceforge.net/projects/zkanji/files/zkanji/v0.7/

      The examples can’t be translated with zkanji but I’m thinking about using multilingual data from the Tatoeba project.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: