Thread overview | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
November 24, 2011 auto | ||||
---|---|---|---|---|
| ||||
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 |
November 24, 2011 Re: auto | ||||
---|---|---|---|---|
| ||||
Posted in reply to RexLen | 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
|
November 24, 2011 Re: auto | ||||
---|---|---|---|---|
| ||||
Posted in reply to RexLen | > 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'. |
November 24, 2011 Re: auto | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | 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
|
November 24, 2011 Re: auto | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Nadlinger | >> 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?
Actually not. Would be interesting, esp. if trySemantic is in the game.
|
November 24, 2011 Re: auto | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | >> 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.
The type has to be deduced anyway for type checking the assignment/initialization.
|
November 24, 2011 Re: auto | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tobias Brandt | > The type has to be deduced anyway for type checking the
> assignment/initialization.
Makes sense. Overseen that.
|
November 24, 2011 Re: auto | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | 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! |
November 26, 2011 Re: auto | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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.
|
November 26, 2011 Re: auto | ||||
---|---|---|---|---|
| ||||
Posted in reply to RexLen | 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"; } |
Copyright © 1999-2021 by the D Language Foundation