Performance test regarding variable declarations. Does Variable declaration matters nowadays?

Luthius

Active Member
Joined
Apr 5, 2011
Messages
315
Guys
I was looking forward a Speed Test or Performance test where is possible measure a code running with declared variables and other without variable declaration.

I saw a lot of discussions about this subject and it always goes to a Best Practice point of view rather then "performance" or error management.
Okay, in my projects I always declare the variables and try my best to proper set the most memory optimized type as possible.
Even some object type I guess is NOT "mandatory" because the VBE "guess" and compile it.

If someone has some speed test or performance test or something that can share it, where shows that it goes beyond best practices, I mean, declare variables really matters for the computer's capacity nowadays (memory, processor, etc.)
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,977
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Not really speed wise unless you have huge data , it is just on a very rare occasion VBA can misinterpret what you want if the value changes from one data type to another (say your initial value was a Long and then you started using Decimals).
The main advantage of declaring your variables is you can use Option Explicit to pick up on typo's.
 

Luthius

Active Member
Joined
Apr 5, 2011
Messages
315
In other words doesn't matter declaring the variables or not. For coding sake I mean.

But I'm curious because variant types demand more usage of memory, so it can jeopardize the speed, right?
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,977
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
It affects the speed but it is a case of how noticeable it is. As I stated the main advantage of declaring them these days is debugging.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,464
Messages
5,624,885
Members
416,064
Latest member
PaulBr2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top