digitalmars.D.learn - auto
- RexLen (7/7) Nov 24 2011 Just curious:
- David Nadlinger (6/12) Nov 24 2011 The actual type »auto« represents is determined during compilation, so...
- Trass3r (7/12) Nov 24 2011 Well the runtime performance is equal but of course compilation takes
- David Nadlinger (4/6) Nov 24 2011 Just curious: I would be surprised if there was actually a measurable
- Trass3r (2/6) Nov 24 2011 Actually not. Would be interesting, esp. if trySemantic is in the game.
- Tobias Brandt (2/5) Nov 24 2011 The type has to be deduced anyway for type checking the
- Trass3r (1/3) Nov 24 2011 Makes sense. Overseen that.
- Andrej Mitrovic (3/3) Nov 24 2011 But I bet you would waste more memory at compile-time if you had to
- Peter Alexander (6/9) Nov 26 2011 Actually, using `auto` should be faster because the compiler doesn't
- mta`chrono (9/9) Nov 26 2011 Did you know that auto is not auto in the way auto behalfs. it's just a
Just curious: is there any performance gap using auto instead of int or other type? For example int[] ar1 = new int[1000]; auto[] ar2 = new int[1000]; are these equivalent by a perfomance point of view? Thx
Nov 24 2011
On 11/24/11 9:59 PM, RexLen wrote:Just curious: is there any performance gap using auto instead of int or other type? For example int[] ar1 = new int[1000]; auto[] ar2 = new int[1000]; are these equivalent by a perfomance point of view?The actual type »auto« represents is determined during compilation, so there is no difference in the final executable. If you wanted to actually use a type not known statically, I'd have a look at std.variant. Hope this helps, David
Nov 24 2011
is there any performance gap using auto instead of int or other type? For example int[] ar1 = new int[1000]; auto[] ar2 = new int[1000]; are these equivalent by a perfomance point of view?Well the runtime performance is equal but of course compilation takes slightly longer since it has to deduce the type first. But in general you should only use auto if it doesn't make your code harder to understand (e.g. auto x = funcThatDoesCrazyShitYouCantGuessFromTheName(); // so, what's the type of x???). Also it's 'auto ar2' instead of 'auto[] ar2'.
Nov 24 2011
On 11/24/11 10:09 PM, Trass3r wrote:Well the runtime performance is equal but of course compilation takes slightly longer since it has to deduce the type first.Just curious: I would be surprised if there was actually a measurable difference between the two – did you ever try to measure it? David
Nov 24 2011
Well the runtime performance is equal but of course compilation takes==slightly longer since it has to deduce the type first.Just curious: I would be surprised if there was actually a measurable =difference between the two =E2=80=93 did you ever try to measure it?Actually not. Would be interesting, esp. if trySemantic is in the game.
Nov 24 2011
The type has to be deduced anyway for type checking the assignment/initialization.is there any performance gap using auto instead of int or other>> type? For example>> >> int[] ar1 = new int[1000];>> auto[] ar2 = new int[1000];>> >> are these equivalent by a perfomance point of view? Well the runtime performance is equal but of course compilation takesslightly longer since it has to deduce the type first.
Nov 24 2011
The type has to be deduced anyway for type checking the assignment/initialization.Makes sense. Overseen that.
Nov 24 2011
But I bet you would waste more memory at compile-time if you had to type a long template instance name instead of using auto. We're talkin' bytes here!
Nov 24 2011
On 24/11/11 10:38 PM, Andrej Mitrovic wrote:But I bet you would waste more memory at compile-time if you had to type a long template instance name instead of using auto. We're talkin' bytes here!Actually, using `auto` should be faster because the compiler doesn't need to do any name lookup. auto x = foo(); // deduce type of Foo and use that Foo x = foo(); // find out what 'Foo' refers to, but also deduce type of foo() and then do type checking.
Nov 26 2011
Did you know that auto is not auto in the way auto behalfs. it's just a placeholder so the compiler can determine that a variable follows. but you can use any other keyword for type interfering, too. void main() { const a = FunctionThatReturnsSomething(); static b = 5.0; scope c = "hey"; }
Nov 26 2011