Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #120809 > unrolled thread
| Started by | Vir Campestris <vir.campestris@invalid.invalid> |
|---|---|
| First post | 2024-10-31 10:21 +0000 |
| Last post | 2024-10-31 07:47 -0400 |
| Articles | 8 — 4 participants |
Back to article view | Back to comp.lang.c++
I'm going to give up on this... Vir Campestris <vir.campestris@invalid.invalid> - 2024-10-31 10:21 +0000
Re: I'm going to give up on this... Michael S <already5chosen@yahoo.com> - 2024-10-31 12:44 +0200
Re: I'm going to give up on this... Vir Campestris <vir.campestris@invalid.invalid> - 2024-10-31 16:43 +0000
Re: I'm going to give up on this... Mad Hamish <newsunspammelaws@iinet.unspamme.net.au> - 2024-11-03 21:46 +1100
Re: I'm going to give up on this... Vir Campestris <vir.campestris@invalid.invalid> - 2024-11-04 21:30 +0000
Re: I'm going to give up on this... Michael S <already5chosen@yahoo.com> - 2024-11-03 13:41 +0200
Re: I'm going to give up on this... Vir Campestris <vir.campestris@invalid.invalid> - 2024-11-04 21:24 +0000
Re: I'm going to give up on this... Sam <sam@email-scan.com> - 2024-10-31 07:47 -0400
| From | Vir Campestris <vir.campestris@invalid.invalid> |
|---|---|
| Date | 2024-10-31 10:21 +0000 |
| Subject | I'm going to give up on this... |
| Message-ID | <vfvlo3$2lbru$1@dont-email.me> |
I have a piece of code that takes a couple of seconds to execute. Or perhaps it takes three times longer, depending on a minor change. The change? If the function declaration is template <typename collection> Masker& Masker::andequals(size_t cachesize, collection& primes) it is fast. But if I tell it what the collection is template<> Masker& Masker::andequals(size_t cachesize, std::vector<Prime>& primes) It takes three times as long to execute. But only with g++, and only with -Ofast optimisation. With clang++ I see no such effect (it's slow all the time) WTF? Andy
[toc] | [next] | [standalone]
| From | Michael S <already5chosen@yahoo.com> |
|---|---|
| Date | 2024-10-31 12:44 +0200 |
| Message-ID | <20241031124424.00002cae@yahoo.com> |
| In reply to | #120809 |
On Thu, 31 Oct 2024 10:21:54 +0000
Vir Campestris <vir.campestris@invalid.invalid> wrote:
> I have a piece of code that takes a couple of seconds to execute. Or
> perhaps it takes three times longer, depending on a minor change.
>
> The change?
>
> If the function declaration is
> template <typename collection>
> Masker& Masker::andequals(size_t cachesize, collection& primes)
>
> it is fast. But if I tell it what the collection is
> template<>
> Masker& Masker::andequals(size_t cachesize, std::vector<Prime>&
> primes)
>
> It takes three times as long to execute.
>
> But only with g++, and only with -Ofast optimisation. With clang++ I
> see no such effect (it's slow all the time)
>
> WTF?
>
> Andy
In the second case it's no longer a template, right?
So, does it became real function instead of inline?
What if
static inline
Masker& Masker::andequals(
size_t cachesize, std::vector<Prime>& primes) {
}
[toc] | [prev] | [next] | [standalone]
| From | Vir Campestris <vir.campestris@invalid.invalid> |
|---|---|
| Date | 2024-10-31 16:43 +0000 |
| Message-ID | <vg0c46$2p361$1@dont-email.me> |
| In reply to | #120810 |
On 31/10/2024 10:44, Michael S wrote:
> In the second case it's no longer a template, right?
> So, does it became real function instead of inline?
> What if
>
> static inline
> Masker&Masker::andequals(
> size_t cachesize,std::vector<Prime>& primes) {
> }
That does indeed make it fast.
So all that guff we've ever said about making things modular, and
breaking functions up into small parts? If you want speed, don't do it.
(clang speed is unaffected).
And Sam, when your psychics come back from lunch let me know ;)
ANdy
[toc] | [prev] | [next] | [standalone]
| From | Mad Hamish <newsunspammelaws@iinet.unspamme.net.au> |
|---|---|
| Date | 2024-11-03 21:46 +1100 |
| Message-ID | <22leij9v1jpq41qf9o8ots5sgaijbar8q3@4ax.com> |
| In reply to | #120812 |
On Thu, 31 Oct 2024 16:43:50 +0000, Vir Campestris
<vir.campestris@invalid.invalid> wrote:
>On 31/10/2024 10:44, Michael S wrote:
>> In the second case it's no longer a template, right?
>> So, does it became real function instead of inline?
>> What if
>>
>> static inline
>> Masker&Masker::andequals(
>> size_t cachesize,std::vector<Prime>& primes) {
>> }
>
>That does indeed make it fast.
>
>So all that guff we've ever said about making things modular, and
>breaking functions up into small parts? If you want speed, don't do it.
Generally a minor loss in speed is much less important than people
being able to tell what's actually happening
>
>(clang speed is unaffected).
>
>And Sam, when your psychics come back from lunch let me know ;)
>
>ANdy
[toc] | [prev] | [next] | [standalone]
| From | Vir Campestris <vir.campestris@invalid.invalid> |
|---|---|
| Date | 2024-11-04 21:30 +0000 |
| Message-ID | <vgbee4$14eft$2@dont-email.me> |
| In reply to | #120828 |
On 03/11/2024 10:46, Mad Hamish wrote: > Generally a minor loss in speed is much less important than people > being able to tell what's actually happening Requirement one: The code works correctly. Requirement two: Your fellow workers can understand why Requirement three: It's fast. There are cases where high speed is a requirement, but in my experience they were rare. And usually benchmarks ;) But there's no point in having a program that is really really fast, but produces the wrong answer. When under some rare circumstances your code does something bad happens your fellow worker might have to fix it, which is why #2. Andy
[toc] | [prev] | [next] | [standalone]
| From | Michael S <already5chosen@yahoo.com> |
|---|---|
| Date | 2024-11-03 13:41 +0200 |
| Message-ID | <20241103134118.00002365@yahoo.com> |
| In reply to | #120812 |
On Thu, 31 Oct 2024 16:43:50 +0000
Vir Campestris <vir.campestris@invalid.invalid> wrote:
> On 31/10/2024 10:44, Michael S wrote:
> > In the second case it's no longer a template, right?
> > So, does it became real function instead of inline?
> > What if
> >
> > static inline
> > Masker&Masker::andequals(
> > size_t cachesize,std::vector<Prime>& primes) {
> > }
>
> That does indeed make it fast.
>
> So all that guff we've ever said about making things modular, and
> breaking functions up into small parts? If you want speed, don't do
> it.
>
I don't quite understand how it follows. Didn't you get it both modular
and fast?
BTW, I strongly suspect that it would be equally fast when you do not
specify 'inline'.
I also suspect, but less strongly, that if you opt for either Global
Program Optimization or Link-time Code Generation then it would be
equally fast even without 'static'. Less strongly, because of absence
of 1st-hand experience with GPO/LTCG on gcc tools.
[toc] | [prev] | [next] | [standalone]
| From | Vir Campestris <vir.campestris@invalid.invalid> |
|---|---|
| Date | 2024-11-04 21:24 +0000 |
| Message-ID | <vgbe37$14eft$1@dont-email.me> |
| In reply to | #120829 |
On 03/11/2024 11:41, Michael S wrote: > I don't quite understand how it follows. Didn't you get it both modular > and fast? > > BTW, I strongly suspect that it would be equally fast when you do not > specify 'inline'. > I also suspect, but less strongly, that if you opt for either Global > Program Optimization or Link-time Code Generation then it would be > equally fast even without 'static'. Less strongly, because of absence > of 1st-hand experience with GPO/LTCG on gcc tools. By using inline, and putting all the code in the same file, I got the speed. I only worked this out after I'd broken the functions out into separate source files (and object files) to find the code was always slow. ANdy
[toc] | [prev] | [next] | [standalone]
| From | Sam <sam@email-scan.com> |
|---|---|
| Date | 2024-10-31 07:47 -0400 |
| Message-ID | <cone.1730375220.967910.84821.1000@ripper.email-scan.com> |
| In reply to | #120809 |
Vir Campestris writes: > I have a piece of code that takes a couple of seconds to execute. Or perhaps > it takes three times longer, depending on a minor change. > > The change? > > If the function declaration is > template <typename collection> > Masker& Masker::andequals(size_t cachesize, collection& primes) > > it is fast. But if I tell it what the collection is > template<> > Masker& Masker::andequals(size_t cachesize, std::vector<Prime>& primes) > > It takes three times as long to execute. > > But only with g++, and only with -Ofast optimisation. With clang++ I see no > such effect (it's slow all the time) > > WTF? We are very sorry to inform you that all of our psychics are on their lunch break, right now, and there's nobody left in the office who's certified to operate our mind ray-beam machine that's required to extract the actual code, for a detailed inspection and analysis, out of your head. We apologize for the inconvenience.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web