Click here to Skip to main content
15,914,447 members
Home / Discussions / C#
   

C#

 
AnswerRe: Help add new section to this config please Pin
Geoff Williams16-Sep-11 6:48
Geoff Williams16-Sep-11 6:48 
GeneralRe: Help add new section to this config please Pin
mwpeck16-Sep-11 7:00
mwpeck16-Sep-11 7:00 
GeneralRe: Help add new section to this config please Pin
PIEBALDconsult16-Sep-11 14:52
mvePIEBALDconsult16-Sep-11 14:52 
GeneralRe: Help add new section to this config please Pin
mwpeck16-Sep-11 15:06
mwpeck16-Sep-11 15:06 
GeneralRe: Help add new section to this config please Pin
PIEBALDconsult16-Sep-11 17:21
mvePIEBALDconsult16-Sep-11 17:21 
GeneralRe: Help add new section to this config please Pin
mwpeck16-Sep-11 17:40
mwpeck16-Sep-11 17:40 
GeneralRe: Help add new section to this config please Pin
PIEBALDconsult16-Sep-11 17:52
mvePIEBALDconsult16-Sep-11 17:52 
QuestionSpeed of execution Pin
Kevin1316-Sep-11 5:10
Kevin1316-Sep-11 5:10 
I have just come to C# after many years of C/C++ and am a bit surprised at the relatively slow speed of C# execution. The following is very simple test piece of code (completely useless) implemented in C# and C. Both tested on the same PC running Windows 7 Professional 64bit
The C# returns between 30 and 45 ms and the C/C++ a stable 4.2 ms.

Is there anything I can do with my C# code to speed it up?

C# Visual Studio 2010 Release Build Optimize On x86
C#
Stopwatch time = new Stopwatch();
int size = 10000000;
byte[] data = new byte[size];
unsafe
{
    fixed (byte* ptr = data)
    {
        time.Restart();
        for (int i = 0; i < size; i++)
            ptr[i] = 128;
        time.Stop();
    }
}
var elapsed = 1000.0 * time.ElapsedTicks / Stopwatch.Frequency;
Console.WriteLine("unsafe time " + elapsed.ToString() +" ms");

C++ Visual Studio 2008 Release Build x86
C++
int size = 10000000;
unsigned char* pData = new unsigned char[size];
QueryPerformanceCounter(&start);
for(int i=0;i<size;i++)
    pData[i] = 128;
QueryPerformanceCounter(&finish);
time = float(finish.QuadPart - start.QuadPart);
time /= Frequency.QuadPart;

char msg[300];
sprintf(msg,"time %f\n",time*1000.0f);
OutputDebugString(msg);
delete pData;


I know I could make both faster with threading but question is really about the execution speed.

Finally after all the postings...

Thanks everyone for their comments suggestions C# is good for a large number of tasks and C/C++ is more appropriate for a different set of tasks.

PS I have not been active in the last week - some places in the world have no wifi or 3G ! http://s.codeproject.com/script/Forums/Images/smiley_smile.gif

modified 27-Sep-11 4:55am.

AnswerRe: Speed of execution Pin
Simon Bang Terkildsen16-Sep-11 5:54
Simon Bang Terkildsen16-Sep-11 5:54 
GeneralRe: Speed of execution Pin
Kevin1316-Sep-11 6:43
Kevin1316-Sep-11 6:43 
AnswerRe: Speed of execution Pin
Matt Meyer16-Sep-11 6:11
Matt Meyer16-Sep-11 6:11 
GeneralRe: Speed of execution Pin
Kevin1316-Sep-11 6:34
Kevin1316-Sep-11 6:34 
GeneralRe: Speed of execution Pin
Matt Meyer16-Sep-11 7:02
Matt Meyer16-Sep-11 7:02 
AnswerRe: Speed of execution Pin
AspDotNetDev16-Sep-11 7:02
protectorAspDotNetDev16-Sep-11 7:02 
AnswerRe: Speed of execution Pin
Luc Pattyn16-Sep-11 7:18
sitebuilderLuc Pattyn16-Sep-11 7:18 
AnswerRe: Speed of execution Pin
Eddy Vluggen16-Sep-11 9:51
professionalEddy Vluggen16-Sep-11 9:51 
GeneralRe: Speed of execution Pin
AspDotNetDev16-Sep-11 10:38
protectorAspDotNetDev16-Sep-11 10:38 
AnswerRe: Speed of execution Pin
Eddy Vluggen16-Sep-11 11:03
professionalEddy Vluggen16-Sep-11 11:03 
GeneralRe: Speed of execution Pin
AspDotNetDev16-Sep-11 11:20
protectorAspDotNetDev16-Sep-11 11:20 
AnswerRe: Speed of execution Pin
Eddy Vluggen16-Sep-11 11:33
professionalEddy Vluggen16-Sep-11 11:33 
NewsRe: Speed of execution Pin
Eddy Vluggen16-Sep-11 13:44
professionalEddy Vluggen16-Sep-11 13:44 
QuestionUndo functionality for Node rename in TreeView Pin
Nyanoba16-Sep-11 1:28
Nyanoba16-Sep-11 1:28 
AnswerRe: Undo functionality for Node rename in TreeView Pin
BillWoodruff16-Sep-11 2:26
professionalBillWoodruff16-Sep-11 2:26 
AnswerRe: Undo functionality for Node rename in TreeView Pin
BobJanova16-Sep-11 3:51
BobJanova16-Sep-11 3:51 
GeneralRe: Undo functionality for Node rename in TreeView Pin
BillWoodruff16-Sep-11 17:01
professionalBillWoodruff16-Sep-11 17:01 

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.