473,320 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

OMG VB.net more efficient than C#??

I was viewing some strange behaviour in c# so I tried a
comparison in vb.net

A simple 1 line console application written in both c# and
vb.net (One line meaning one line in the main function).

Console.WriteLine(100L)

It appears vb.net declares a 8 byte long and stores the
value into it before calling the console.writeline method
which is what I would expect. However in c# it declares a
4 byte variable, and converts it to an 8 byte long,
wasting one extra instruction call.

Is this behaviour a bug in the framework or in fact vb.net
is more efficient at handling longs as apposed to c#.

The msil code for both programs is included below..

VB.net code ++++++++++++++++++++++++++++++++
..method public static void Main() cil managed
{
.entrypoint
.custom instance void [mscorlib]
System.STAThreadAttribute::.ctor() = ( 01 00 00 00 )
// Code size 15 (0xf)
.maxstack 8
IL_0000: ldc.i8 0x64
IL_0009: call void [mscorlib]
System.Console::WriteLine(int64)
IL_000e: ret
} // end of method Module1::Main

c# code ++++++++++++++++++++++++++++++++++++++++++++
..method private hidebysig static void Main(string[] args)
cil managed
{
.entrypoint
.custom instance void [mscorlib]
System.STAThreadAttribute::.ctor() = ( 01 00 00 00 )
// Code size 9 (0x9)
.maxstack 1
IL_0000: ldc.i4.s 100
IL_0002: conv.i8
IL_0003: call void [mscorlib]
System.Console::WriteLine(int64)
IL_0008: ret
} // end of method Class1::Main

Nov 15 '05 #1
1 1480
<an*******@discussions.microsoft.com> wrote in news:068c01c398f3$73e358e0
$a*******@phx.gbl:
Is this behaviour a bug in the framework or in fact vb.net
is more efficient at handling longs as apposed to c#.


VB.NET isn'T better...
it makes no difference. don'T forget :that'S just immediate language.
It needs to be optimized by the jit compiler anyways.
and I'd say that the c# version will be better for optimizing:
..)the jit works with 32bit ints on the execution stack. -> pushing 4bytes
on it is faster than 8bytes -> c# compiler has noted that there is a value
small enough for int
..)converting on the execution stack to long is efficient. on a 64bit cpu
the JIT may translate to simply setting a flag. or even better when he sees
what is happening with that long he might decide some other optimization.
in the vb.net version he'S forced to work with 2 32bit slots on the
execution stack.

what's more interesting is that VB.NET reserves a maximum stack size of 8
items. imho that'S not necessary for such a simple function.

--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Narendra C. Tulpule | last post by:
Hi, if you know the Python internals, here is a newbie question for you. If I have a list with 100 elements, each element being a long string, is it more efficient to maintain it as a dictionary...
6
by: Mike O. | last post by:
What's the most efficient way to store small messages (similar in size to a short email) on the client without using a database? I need to be able to store thousands possibly. I was thinking of...
3
by: sandeep | last post by:
Hi i am new to this group and to c++ also though i have the knowledge of "c" and now want to learn c++ and data structure using c/c++ . so could nebody please suggest me some...
2
by: Vance M. Allen | last post by:
Greetings, I am establishing a database for the purpose of logging access to my secure webserver and am wanting to make the database as efficient as I can because it will be doing a lot of work...
3
by: Brian Wotherspoon | last post by:
I have a table with data that is refreshed regularly but I still need to store the old data. I have created a seperate table with a foreign key to the table and the date on which it was replaced. ...
5
by: Alan Little | last post by:
I have affiliates submitting batches of anywhere from 10 to several hundred orders. Each order in the batch must include an order ID, originated by the affiliate, which must be unique across all...
21
by: py_genetic | last post by:
Hello, I'm importing large text files of data using csv. I would like to add some more auto sensing abilities. I'm considing sampling the data file and doing some fuzzy logic scoring on the...
1
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
Using .NET 2.0 is it more efficient to copy files to a single folder versus spreading them across multiple folders. For instance if we have 100,000 files to be copied, Do we copy all of them to...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
25
by: Abubakar | last post by:
Hi, recently some C programmer told me that using fwrite/fopen functions are not efficient because the output that they do to the file is actually buffered and gets late in writing. Is that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.