Is it possible to make a vb.net application faster
Through code like using characters that the Computer already understands
Like coding in certain areas through y x (math) etc.
Will it be More faster since the compiler don't have to really do much work
But its still must be VB.NET <Basic ways to make my apps faster>
:-/

I don't see how the compiler fits in this, as it's only used during creation and not execution (vs interpreter who is invoked at run-time).
I've seen an article about it, but was more about what to place in a loop and what not to or where to use vars/constants or calculations and if I remember correctly it concluded that unless you've done some serious design flaws or use extensively loops you won't get a much faster program by following these instructions.

What is your program supposed to do? Where are you facing delays?

No im not Facing any delays but im just thinking about how to program like a Pro

Im thinking about when to use Certain code and how to Declare it

and is there a difference when you declare something through words or Just chars

Not everything programmed in C++ is faster than VB.NET. It is just matter of using the right data structure and the right algorithm for your problem.

commented: nice +1

yes C++ really faster than VB.NET

As VB.NET already says it in its name... your application need to inject .NET code at runtime (which C++ don't need to)
Beside that, the speed is also the result of a clean and productive coding style. Means if the coder have unnecessary loops, checks or using a hell of global variables the program will slow down of course.

Just a comment: Who said that pros write fast performing code? Nowadays most programmers don't really care about resources and execution time. In fact it's been a while since I've come across a programmer that took into account stuff like that or how to facilitate the user/ respect the flow of the process, etc.

On your programms keep it simple, well commented and recycle code whenever possible.

yes C++ really faster than VB.NET

I don't think you get my idea. Not everything written in C++ is faster then VB.NET. If C++ program is using the wrong algorithm for the problem, VB.NET that using the right algorithm will perform better.

your application need to inject .NET code at runtime (which C++ don't need to)

Indeed, C++ program is translated into native code, so do .NET program. The process of .NET gone like this:

  1. Every .NET program is compiled into CIL(Common Intermediate Language)
  2. When .NET program is run, CIL code will get translated into native code (through Just-In-Time Compiler)
  3. Then native code is executed.

The end result is the same which is in NATIVE CODE. To me, the reason that .NET program run slower because of garbage collector and other managed libraries. However, for safer program, there should be a trade-off.

So what is my point? My point is that VB.NET beginner programmer most of time will produce a faster program than C++ beginner programmer, because VB.NET beginner will use right tool provided my .NET libraries which is a wrapper of good implemented native code. Moreover, VB.NET beginner probably tend to make less optimization mistake. For example:

VB.NET version

Private Function IsPrime(ByVal n As Long) As Boolean
        For i As Integer = 2 To Math.Sqrt(n)
            If n Mod i = 0 Then
                Return False
            End If
        Next

        Return True
    End Function

C++ version assuming compiling with no compiler optimization

bool IsPrime(long n) {
    for(int i=2;i<sqrt(n);i++)
        if ((n % i) == 0)
            return false;
    return true;
}

As n grows larger, VB.NET will start to run faster.

Reply to Adam_K and to the rest:icon_cheesygrin:

of course i like to balance my code in order
So that i know where things are and how they progress and i don't use comments
It might not be executed in the program but i like to think so :D :D :) :P
So yea but there's one thing is still like to know
Is there any difference how you declare some thing
So instead using long names myvidoechannel = "" or just use x = ""
Any difference People :D

and please if im wrong don't make me look like an ass :icon_evil:
some of the people on DaniWeb have the urge to do it :icon_mad:

Naming your variable (long or short) does not affect the performance because once it is compiler, it will be just a piece of memory address.

OH that's a shame :(
But still is there anything like what i suggested that can give performance problems
or some other to make it faster any kind of coding like the steps of making sure that it would not be memory thirsty like doing this when you not doing that like a vb guide. Please i would really appreciate it
:)

I should really not dwell on this part because i don't know half of .Nets capabilities and its functions :D im still NEWBIE BEGINNER i should know more because i started in 2009
But im in High School Going to grade 11 Next Year omw :D its gonna be like Hell
Anyway any help or link is cool

If I remember correctly it is slower to run:

for i= 1 to datagrid1.rows.count -1 'or whatever count that is

than

dim row_count as int 
row_count = datagrid1.rows.count
for i=1 to row_count

The explanation is that in the first syntax the number of rows has to be calculated in every loop, while in the second it doesn't.

So the second one is faster

Member Avatar for Unhnd_Exception

Your not going to learn how to write faster code from this thread. A good way to learn how to write faster code is to write more code. Learn whats faster by setting timers in your code.

The only thing I'll say to this is: Integer is the fastest. When ever you can use an integer use it. Select case can be faster than If block. If you use an If block then use short circuiting. Look at your code when your done. Try to eliminate wasted logic. If you need to calculate things more than once make sure it doesn't happen more than once. You will learn as you go.

Write a block of code you want faster. Lets see if we can make it faster.

The explanation is that in the first syntax the number of rows has to be calculated in every loop, while in the second it doesn't.

The second does not run faster. In VB.NET, For Loop does pre-calculate for us. For example:

Dim ending As Integer = 10
Dim count As Integer = 0

For i As Integer = 0 To ending
   ending = 1
   count += 1
Next

Msgbox(count)

It will run from 0 to 10 even though you change the ending to 1. Unlike C++. That's why I said that C++ beginner programmer will more likely to make more mistake.

Maybe you can try to play around with ProjectEuler problems. Each problem is fun to solve and you will learn how to optimize your code by looking at other people approach.

Thanks for your help guys Thread Solved

Not sure if this helps, though I did notice it in an online.thread a while ago and it has been w/.Me ever since; in mind, Not programming(for now at least).

Public Class Form1
    Private sTemp As String
   
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        sTemp = "some textString"
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        MsgBox(sTemp) '// get.Value.
        '////////////////
        sTemp = Nothing '// .Clear String once value has been used.
        '\\\\\\\\\\\\\\\\\\\
    End Sub
End Class

I think that by .Clearing out the Values to Nothing, might clear up the system one way or another. Again, assumption, though I like.:)

I do not understand what do you mean by "clear up the system". From my experience, "some textString" is a constant that will compiled and stored in executable file. Once the program run, it will load into memory. sTemp hold the address to the "some textString" address. When sTemp assigned to Nothing then sTemp will no longer hold the address of "some textString". So of course, it seem like it clear all value of sTemp. However, in reality, you just assign a new value to sTemp instead of clearing its value.

So what's happening to the "some textString"? It will be in memory and it will be always there until someone directly access to the memory and change its value, but since constant variables are stored in read-only memory, I doubt you can change it easily.

This is just my opinion, feel free to correct me.

invisal, some good info provided, thanx, though...
I believe that when you clear a Variable to Nothing, especially a String, it sets the .Value to "";which contains "no" characters at all.
By doing so, you should clear the memory just a little, even if only by a few characters here and there.

I did mention<<Not sure if this helps
.and I was and still am quite uncertain that it does help to clear To Nothing, though it seems like it should; just from those few little characters not using up memory, If Not needed.

It does not clear variable to nothing. You just assign new value to the existed variable. Each time you declare a variable, you allocate a piece of memory to store it value. Now, sTemp, in your example, is a variable that store the address of a string. Address of memory is just a piece of number. Whether it is an address of "some textString" or it is an address of Nothing, it will consume the same amount of memory to store address of memory.

.quite interesting invisial.
I'll stick to .My idea on the topic that Nothing clears out the memory of certain/If Not all things(:mostly due to being a hobbyist programmer/etc.:), and hopefully someday someone will read this thread and actually do something about it; as to clearing out those unnecessary characters out of someone's memory..
.Afterall, think big, and big things might happen; it is God's world after all(says quite a few folk, more than 90%+ of the world's population.
.andAlso, nope, not bringing religion to the table, for I have faith in life, not God.

I did not mean assign a variable to Nothing does not help anything. There is thing called Garbage Collector which clear unused memory. If particular memory address proved to be unused (probably no variable hold its address anymore), then it will free the memory. However, in your example, it does not help because that string you want to free is a constant and it's always needed.

commented: Garbage Collector?; forgot about it, hobbyist and all.thanx. :) +12

Guys Stop Fighting i know that its impossible to make it run faster
But there are some area's were you can win speed by coding Right okay people
Now Chill :P

commented: thanx for forum.concern:) +12

>>Now Chill
NO! What are you going to do about it? xD
(jk)
.was not a fight, was understanding each other's.solid terms, Nothing Else.
.thanx for concern, +=1 for you as well.:)

Member Avatar for Unhnd_Exception

VB 2012

Heres an example of how the actual code makes a difference. VB.net is plenty fast. Most things can be improved just by changing the code.

Take a look at this thread I replied to you.
http://www.daniweb.com/software-development/vbnet/threads/398577

The section on there where it updates the workers progress. I said you don't want to update the progress bar every time. And thats true. It is supposed to update the progress bar every 5%. It does but it updates the progress bar at every 5% many times.

Heres what it does

Say you have a total file length of 1,000 and you want to update the progress bar every 5%

This applies to the example I provided in the other thread.

50 / 1000 = .05 * 100 = 5%
51 / 1000 = .051 * 100 = 5.1% but CInt(5.1) = 5
52 / 1000 = .052 * 100 = 5.2% but CInt(5.2) = 5

You can see 5% can be created many different ways so the progress bar is being updated unnecessary.

I made a mod to that.


I added a boolean array to check if 5% had already been set before updating the progress bar.


Dim PercentCompleteSet(100) As Boolean

That was added at the top of the code block. So in the thread I'm describing it would be right under Buffer(99). The variable now contains 0 - 100.

When updating the background workers progress it checks if that percentage has already been updated. If it has it doesn't do anything. If it hasn't It updates the progress bar and sets the percentage to true in the PercentCompleteSet array so it is skipped next time.

So the background worker report progress line of code would look like this now.

PercentComplete = CInt((TotalBytesRead / TotalBytesInFiles * 100))

If PercentComplete < 0 Then
     PercentComplete = 0
ElseIf PercentComplete > 100 Then
     PercentComplete = 100
End If

If PercentCompleteSet(PercentComplete) = False AndAlso PercentComplete Mod 5 = 0 Then
     BackgroundWorkerRestore.ReportProgress(PercentComplete)
     PercentCompleteSet(PercentComplete) = True
End If

With that example the progress bar is only updated 1 time every 5%.

This is nothing but an example of how tweaking your code can make massive changes. If your still running that code I provided, changing the above out will make the progress bar remarkably faster.

commented: "just because" I'm glad to have you as a friend again on my Daniweb.Friends.List.:) All the best to you and don't ever forget the "code.order".:) btw, it's only -=3 for.now.:D -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.