.::Eralp Erat's Solutions Diary::..

{#Every way that I Can share!}-MS Dynamics CRM-Sharepoint-Mobility-Infopath

Speed Test: Switch vs If-Else-If

clock Mayıs 31, 2011 11:50 by author NetZero2

The .NET framework and the C# language provide two methods for conditional processing where multiple discrete values can be selected from. The switch statement is less flexible than the if-else-if ladder but is generally considered to be more efficient.

This test was designed to compare the execution time of the switch statement and the if-else-if ladder code structure when used to select a match from a discrete series of values. The if-else-if ladder provides much greater flexibility than is used by the test but, when being used to provide matching functionality to switch, this does not need to be considered. The two conditional processing structures are described in the article, C# Program Flow Control: Conditional Processing.

Test Process Functionality

It was important that the speed test for the two statements provided exactly the same functionality in both cases. For each test, an integer value between zero and nineteen was generated. This integer value was then compared against nineteen possible selections using if commands and case statements. Where the integer value generated was nineteen, this was not matched and instead processed using the final else statement or the switch command's default case.

In many programming situations, a selection of this kind is very likely to generate a match. However, for completeness, a second test was performed. This test followed the same functionality but using an integer value that did not match any of the possible values; it therefore always used the final else statement or the switch command's default case.

Looping

The speed of execution of a large if-else-if ladder or select statement is too fast to be accurately measured. To make measuring possible and to reduce anomalies, a loop was constructed and the test code executed repeatedly. For each test, the loop completed one billion (1,000,000,000) iterations.

The looping function for the first test was used to generate the integer value to match. For each iteration in a for loop, the loop control variable was used with the modulus operator to create a comparison value between zero and nineteen.

In addition to executing the test with value-matching and the test without value-matching, the loop code was executed with no internal test code. Two versions of empty loop were used, one with the number generation code and one without. These two tests provided baseline timings that could be subtracted from the actual test times.

Timing

The timing of the tests was controlled automatically using the Stopwatch class. Each test was performed repeatedly and the mean average of the results calculated.

Test Conditions

Hardware

The test results included below are those produced using an Athlon64 3200+ with 4GB RAM. These tests are indicative of further relative test results that were carried out on a variety of equipment including:

  • IBM ThinkPad R51 notebook with a 1.6GHz processor and 2GB RAM
  • JVC MiniNote notebook with a 1GHz processor and 768MB RAM

The tests were executed using three operating systems, each with the latest service packs and patches. These were:

  • Windows XP
  • Windows Server 2003 R2
  • Windows Vista Ultimate

In each test, the software was compiled as a .NET framework 2.0 console application in three configurations:

  • Compiled for 32-bit processors only using Visual Studio 2005 Team Edition
  • Compiled for 32-bit or 64-bit processors using Visual Studio 2005 Team Edition
  • Compiled using Visual C# 2005 Express Edition

Results

Raw Results

This table shows the timings for the empty loop, if statement and switch statement for one billion iterations rounded to the nearest millisecond. The two columns show the results for the loops where matching of the comparison value occurs and for the non-matching tests.


MatchingNon-Matching
Empty Loop 27.3s 5.0s
Switch Statement 43.0s 5.0s
If Statement 48.0s 5.1s

Adjusted Results

This second table shows the results for the two key test types, adjusted to remove the delay created by the looping mechanism.


MatchingNon-Matching
Switch Statement 15.7s 0.0s
If Statement 20.7s 0.1s

Conclusion

The results show that the switch statement is faster to execute than the if-else-if ladder. This is due to the compiler's ability to optimise the switch statement. In the case of the if-else-if ladder, the code must process each if statement in the order determined by the programmer. However, because each case within a switch statement does not rely on earlier cases, the compiler is able to re-order the testing in such a way as to provide the fastest execution.

 

Look At : http://www.blackwasp.co.uk/SpeedTestIfElseSwitch.aspx 

7 kişi tarafından 4.4 olarak değerlendirildi

  • Currently 4,428571/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Differences Between C++ Templates and C# Generics (C# Programming Guide)

clock Ekim 26, 2010 04:25 by author NetZero2

 

 

C# Generics and C++ templates are both language features that provide support for parameterized types. However, there are many differences between the two. At the syntax level, C# generics are a simpler approach to parameterized types without the complexity of C++ templates. In addition, C# does not attempt to provide all of the functionality that C++ templates provide. At the implementation level, the primary difference is that C# generic type substitutions are performed at runtime and generic type information is thereby preserved for instantiated objects. For more information, see Generics in the Runtime (C# Programming Guide).

The following are the key differences between C# Generics and C++ templates:

  • C# generics do not provide the same amount of flexibility as C++ templates. For example, it is not possible to call arithmetic operators in a C# generic class, although it is possible to call user defined operators.

  • C# does not allow non-type template parameters, such as template C<int i> {}.

  • C# does not support explicit specialization; that is, a custom implementation of a template for a specific type.

  • C# does not support partial specialization: a custom implementation for a subset of the type arguments.

  • C# does not allow the type parameter to be used as the base class for the generic type.

  • C# does not allow type parameters to have default types.

  • In C#, a generic type parameter cannot itself be a generic, although constructed types can be used as generics. C++ does allow template parameters. ( :))) )

  • C++ allows code that might not be valid for all type parameters in the template, which is then checked for the specific type used as the type parameter. C# requires code in a class to be written in such a way that it will work with any type that satisfies the constraints. For example, in C++ it is possible to write a function that uses the arithmetic operators + and - on objects of the type parameter, which will produce an error at the time of instantiation of the template with a type that does not support these operators. C# disallows this; the only language constructs allowed are those that can be deduced from the constraints.

Source : MSDN

4 kişi tarafından 5.0 olarak değerlendirildi

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


MS Dynamics Crm Tips And Tricks - 28 (Microsoft CRM ,plug'in içerisinde parametre pas geçme)

clock Haziran 11, 2010 02:18 by author NetZero2

Selamlar ;

Yüksek lisans final sınavları, müşteri tarafındaki yoğunluk ve kızım Zeynep'le uğraşırken ancak yazabilmeye fırsatım oluyor.Lütfen mazur görün.

Geçenlerde müşteri tarafında ki bir plug'in de geliştirilen iş mantığından ötürü ihtiyaç duyduğum bir olayın çözümünü araştırırken context'ler arasında parametre pas geçebilme özelliğinin olduğunu gördüm.Aşağıda bir örnekle gösterdim.Aynı entity'e regist ettiğim pre ve post eventlerinde değerler birbirine pass geçiliyor.

   12     public class AccountSetStatePreHandler : IPlugin

   13     {

   14         public void Execute(IPluginExecutionContext context)

   15         {

   16             // Post eventinde ihtiyacımız olan datayı alıyoruz.

   17             // Bu örnek

   18             // içerisinde bir guid bilgisini 

   19             // parametre geçiyor olacağız.

   20             Guid contact = new Guid("{74422D5C-381A-4863-A5B9-B8604615C2D0}");

   21 

   22             // Bu işi gerçekleştirecek olan SharedVaraiables container'ini kullanıyor

   23             // olacağız ve buna bir key vermemeiz gerekiyor.PrinCon veriyoruz

   24             context.SharedVariables.Properties.Add(

   25                 new PropertyBagEntry("PriCon", (Object)contact.ToString()));

   26             // Bu şekildede set edebilirsiniz : context.SharedVariables["PrimaryContact"] = contact.ToString();

   27         }

   28     }

   29 

   30     public class AccountSetStatePostHandler : IPlugin

   31     {

   32         public void Execute(IPluginExecutionContext context)

   33         {

   34             // İlgili key shared variables'da varmı kontrol ediyoruz!

   35             if (context.SharedVariables.Contains("PriCon"))

   36             {

   37                 Guid contact =

   38                     new Guid((string)context.SharedVariables["PrimaryContact"]);

   39                 // Artık ilgili key'i elde ettiğimize göre ilgili diğer işlemleri yapabiliriz..

   40             }

   41         }

   42     }

   43 

Önemli bir not , bu özellik CRM 3.0 in arhitect'inde yer alan callout yapısında malesef bulunmuyor.Bunun için custom attribute olusturup (entity bazında ilgili değerleri retrieve edebilirsiniz.)bunları kullanmanız mümkündür(3.0 ve 4.0 için).PropertyBag'ler ile context üzeirinden read/write olan yapılar 4.0'a has bir özelliktir.

Sevgiler.

E2 

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Yazar Hakkında

Eralp

Uludağ Üniversitesi bilgisayar programcılığı sonrasında işletme fakültesini bitiren Erat ; 1999 yılından bu yana yazılım sektörünün içerisinde yer almış ve ilgili olduğu projelerin çözüm üretilmesin de aktif olarak rol oynamıştır.Yaklaşık 6 yılını Türkiye’nin dört bir tarafında yer alan devlet hastanelerin bilgi yönetim sistemlerini tasarlamak ve geliştirmekle geçirmiş ; LIS , IVR ve Linux sistemlerinin entegrasyonu konusunda uzmanlaşmıştır.Bu konuda halen danışmanlık hizmeti vermektedir..Uzun yıllar “Object Pascal” ile uygulama geliştirmiştir.MCP , MCAD.NET ve MCSD.NET,MCTS (MS CRM 4 Customization) unvanlarına sahiptir..Aynı zamanda Mobile Cihazlar konusunda 2007 yılında Microsoft tarafından MVP unvanına layık görülmüştür.
Çeşitli kurumsal projelerin mimari tasarım ve yazılımlarını gerçekleştirmiştir.Son zamanlarda ağırlıklı olarak Microsoft Dynamics CRM ,Sharepoint ve entegrasyon bazlı olarak Axapta(Microsoft ERP) & Project Server ayrıca  IPAD,IPhone,Android (kurumsal ağırlıklı) projelerinde yer almaktadır.CRM ve Sharepoint konusunda başta finans sektörü olmak üzere Türkiye'nin alanında en büyük firmalarına kurumsal eğitimler vermektedir.Yazılım konusunda en büyük hayali, Türkiye’mizin bir yazılım üssü haline gelebilmesinde ön ayak olmaktır. Yazılımın belli bir forma sıkıştırılmasından hiç haz etmeyen ve fanatikliği değil sadece kaliteyi ön plana çıkarabilmek adına deneyimlerini ve yeni teknolojiler hakkında oluşan bilgi ve birikimlerini üniversitelerde genç dimağlarla paylaşmaktan büyük mutluluk duymaktadır.Pragmalinq Yazılım şirketinin kurucusudur.2007 yılında Boğaziçi Üniversitesi Makine Mühendisliği bölümünde C# eğitimleri vermiştir.Şu an Sakarya Üniversitesi Bilgisayar Mühendisliği 3.sınıfta olup paralelde e-Bilişim Mühendisliği dalında yüksek lisans yapmaktadır.

Kişisel İletişim İçin :  eralp.erat@gmail.com

 

infopath 2010



Cozumpark Bilisim Portali

 

Calendar

<<  Şubat 2012  >>
PaSaÇaPeCuCuPa
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

Sign in