Click here to Skip to main content
15,887,337 members
Home / Discussions / C#
   

C#

 
Questionhow can i create a new bitmap file? Pin
lowiq28-Apr-04 20:35
lowiq28-Apr-04 20:35 
AnswerRe: how can i create a new bitmap file? Pin
CWIZO28-Apr-04 20:58
CWIZO28-Apr-04 20:58 
GeneralRe: how can i create a new bitmap file? Pin
lowiq29-Apr-04 3:42
lowiq29-Apr-04 3:42 
AnswerRe: how can i create a new bitmap file? Pin
Heath Stewart29-Apr-04 3:44
protectorHeath Stewart29-Apr-04 3:44 
GeneralPerformance Issues Pin
Member 105947128-Apr-04 19:59
Member 105947128-Apr-04 19:59 
GeneralRe: Performance Issues Pin
Meysam Mahfouzi28-Apr-04 20:39
Meysam Mahfouzi28-Apr-04 20:39 
GeneralRe: Performance Issues Pin
Heath Stewart29-Apr-04 3:40
protectorHeath Stewart29-Apr-04 3:40 
GeneralRe: Performance Issues Pin
Jeff Varszegi29-Apr-04 4:30
professionalJeff Varszegi29-Apr-04 4:30 
Boxing is very expensive, and I always avoid it, but even casting can introduce more performance drain than you may think. Try running this code on your setup to see what I mean.

<br />
            long startTime, endTime;<br />
            int loopCount = 10000000;<br />
            <br />
            Guid guid = Guid.NewGuid();<br />
            Guid guid2 = guid;<br />
            object o = guid;<br />
            object[] objectArray = {guid};<br />
            Guid[] guidArray = {guid};<br />
<br />
            startTime = DateTime.Now.Ticks;<br />
            for(int x = 0; x < loopCount; x++) {<br />
                guid = (Guid)objectArray[0];<br />
                guid = (Guid)objectArray[0];<br />
                guid = (Guid)objectArray[0];<br />
            }<br />
            endTime = DateTime.Now.Ticks;<br />
            Console.WriteLine(((endTime - startTime) / 10) + " microseconds total (accessing array of objects)");<br />
            <br />
            startTime = DateTime.Now.Ticks;<br />
            for(int x = 0; x < loopCount; x++) {<br />
                guid = guidArray[0];<br />
                guid = guidArray[0];<br />
                guid = guidArray[0];<br />
           }<br />
            endTime = DateTime.Now.Ticks;<br />
            Console.WriteLine(((endTime - startTime) / 10) + " microseconds total (accessing array of Guids)");<br />
            <br />
            startTime = DateTime.Now.Ticks;<br />
            for(int x = 0; x < loopCount; x++) {<br />
                guid = (Guid)o;<br />
                guid = (Guid)o;<br />
                guid = (Guid)o;<br />
            }<br />
            endTime = DateTime.Now.Ticks;<br />
            Console.WriteLine(((endTime - startTime) / 10) + " microseconds total (assigning Guid from object w/ cast)");<br />
            <br />
            startTime = DateTime.Now.Ticks;<br />
            for(int x = 0; x < loopCount; x++) {<br />
                guid = guid2;<br />
                guid = guid2;<br />
                guid = guid2;<br />
            }<br />
            endTime = DateTime.Now.Ticks;<br />
            Console.WriteLine(((endTime - startTime) / 10) + " microseconds total (assigning Guid from Guid)");<br />
<br />
            Environment.Exit(0);<br />
 <br />


This gave the following output on my setup, a dual P4 Xeon workstation running VS.NET 2003 in Debug mode:
468750 microseconds total (accessing array of objects)
421875 microseconds total (accessing array of Guids)
484375 microseconds total (assigning Guid from object w/ cast)
375000 microseconds total (assigning Guid from Guid)


Casting overhead is actually one of the major performance drains when using generic collections, after things like method-call overhead and synchronization. I'm not saying that nobody should use collections, but it's good to know how you're spending cycles. I agree with maysam; there's no reason to cast unnecessarily, and good reasons to avoid it.


Regards,

Jeff Varszegi

EEEP!
GeneralRe: Performance Issues Pin
Heath Stewart29-Apr-04 4:42
protectorHeath Stewart29-Apr-04 4:42 
GeneralRe: Performance Issues Pin
Jeff Varszegi29-Apr-04 4:53
professionalJeff Varszegi29-Apr-04 4:53 
GeneralA question about TabletPC SDK Pin
Member 94012528-Apr-04 18:45
Member 94012528-Apr-04 18:45 
GeneralRe: A question about TabletPC SDK Pin
Heath Stewart29-Apr-04 3:38
protectorHeath Stewart29-Apr-04 3:38 
GeneralDeloyment Question Pin
Larry J. Siddens28-Apr-04 16:19
Larry J. Siddens28-Apr-04 16:19 
GeneralRe: Deloyment Question Pin
Tarakeshwar28-Apr-04 18:27
Tarakeshwar28-Apr-04 18:27 
GeneralRe: Deloyment Question Pin
Heath Stewart29-Apr-04 3:32
protectorHeath Stewart29-Apr-04 3:32 
GeneralRe: Deloyment Question Pin
Heath Stewart29-Apr-04 3:37
protectorHeath Stewart29-Apr-04 3:37 
GeneralSelfish LOCK! Pin
CiVerDream28-Apr-04 14:20
CiVerDream28-Apr-04 14:20 
GeneralRe: Selfish LOCK! Pin
Jeff Varszegi28-Apr-04 14:52
professionalJeff Varszegi28-Apr-04 14:52 
GeneralRe: Selfish LOCK! Pin
Heath Stewart29-Apr-04 3:32
protectorHeath Stewart29-Apr-04 3:32 
GeneralRe: Selfish LOCK! Pin
scadaguy28-Apr-04 15:37
scadaguy28-Apr-04 15:37 
Generalcrystal report export to excel Pin
econnor28-Apr-04 11:58
econnor28-Apr-04 11:58 
GeneralRe: crystal report export to excel Pin
Heath Stewart28-Apr-04 12:47
protectorHeath Stewart28-Apr-04 12:47 
GeneralAbout ArrayList. Help! Pin
wk_vigorous28-Apr-04 11:52
wk_vigorous28-Apr-04 11:52 
GeneralRe: About ArrayList. Help! Pin
Christian Graus28-Apr-04 12:00
protectorChristian Graus28-Apr-04 12:00 
GeneralRe: About ArrayList. Help! Pin
Colin Angus Mackay28-Apr-04 12:29
Colin Angus Mackay28-Apr-04 12:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.