.net
Pittsburgh Code Camp 2011.1
http://pghdotnet.org/?page_id=46
Registration Now Open for April 30, 2011 Code Camp!
Pittsburgh .Net Code Camp 2011.1 will be held April 30, 2011 on the campus of Robert Morris University from 9:00 am to 5:00 pm. Registration will open at 8:30. The schedule of presentations will be available soon after we close the call for speakers. Please note that the schedule will be subject to change, as sometimes unforeseen events prevent a presentation from taking place.
Directions to RMU can be found here. Parking is free in the Upper Massey Lot (#4 on the parking map, found here) and the event itself will be in the Hale Center, northwest of the Upper Massey Lot. Most sessions will be on the second floor – handicap access is available via the elevator on the third floor (you pass the third floor entrance of the building first). The second floor can be access via stairways on the third floor or by entering around the building, which enters at the second floor. Lunch will be provided, and we are hoping to make coffee available in the morning.
Code Camp 2010.1
REGISTRATION IS NOW OPEN: Register Here
|
Saturday, April 17th, 2010 9 am - 5 pm (registration 8 - 9 am) Home of the CS Dept. at Sennott Square |
Department of Computer Science Sennott Square University of Pittsburgh Pittsburgh, PA 15260 |
Code Camp is a free, 1-day event put on by the local Pittsburgh community to help promote software development in the community.
Code Camps have been taking place all over the country. This is Pittsburgh's version of this excellent event. The continuing goal of the Code Camps is to provide an intensive developer-to-developer learning experience that is fun and technically stimulating.
All training, slides, manuals, and demo code are provided free following the event!
Our Code Camp will be hosted at the University of Pittsburgh Computer Science Department. We have local speakers from the community who will share their technical expertise and experiences.
Devlink
When:
August 13 - 15, 2009
Registration Opens:
April 1, 2009
Registration Closes:
July 30, 2009 (CLOSED)
Cost:
Standard Ticket - $100
Where:
Lipscomb University
One University Park Drive
Nashville, TN 37204
If vs Ternary: Deathmatch
1: INTRO
The Fun With the ?? Operator in C#: if { } or ?? – Which is Faster? article by Keith Elder got me thinking about the if statement and the ternary operator.
Is there a real difference or are they both the same?
To answer this question I put together a little project that tests both cases and times them.
2: CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | using System; using System.Diagnostics; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] strArray = new string[20000]; Random r = new Random((int)DateTime.Now.Ticks); for (int i = 0; i < 500; i++) { int rnum = r.Next(); if (rnum % 2 == 0) { strArray[i] = null; } else { strArray[i] = rnum.ToString(); } } TimeSpan ts1 = TimeSpan.Zero; TimeSpan ts2 = TimeSpan.Zero; for (int i = 0; i < strArray.Length; i++) { ts2 = ts2.Add(countWithTernary(strArray)); ts1 = ts1.Add(countWithIf(strArray)); } for (int i = 0; i < strArray.Length; i++) { ts1 = ts1.Add(countWithIf(strArray)); ts2 = ts2.Add(countWithTernary(strArray)); } Console.WriteLine(" if: " + ts1.TotalMilliseconds.ToString()); Console.WriteLine("ternary: " + ts2.TotalMilliseconds.ToString()); Console.ReadLine(); } private static TimeSpan countWithIf(string[] arr) { Stopwatch sw = new Stopwatch(); int len = arr.Length; int count = 0; sw.Start(); for (int i = 0; i < len; i++) { if (arr[i] == null) { count += 1; } else { count += 2; } } sw.Stop(); return sw.Elapsed; } private static TimeSpan countWithTernary(string[] arr) { Stopwatch sw = new Stopwatch(); int len = arr.Length; int count = 0; sw.Start(); for (int i = 0; i < len; i++) { count += arr[i] == null ? 1 : 2; } sw.Stop(); return sw.Elapsed; } } } |
3: RESULTS
The output of the above code suprised me, here are the results:
Here we see that using the if statement is much faster than the ternary operator.
In release the if statement gets faster and the ternary stays about the same.
Surprising to me here was when compiled with x64 the if statement was just as slow (or even slower) than the ternary one.
In release for the x64 they're both almost the same again but the ternary operation is faster than the x86 version.
4: CONCLUSION
In conclusion i think using the if statement would be faster in most cases although in most applications the difference would be unnoticeable.

