From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 130072 invoked by alias); 9 Mar 2018 02:33:45 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 130057 invoked by uid 89); 9 Mar 2018 02:33:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-6.0 required=5.0 tests=BAYES_00,FORGED_HOTMAIL_RCVD2,FREEMAIL_FROM,GIT_PATCH_2,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=a1, b1, H*r:sk:BN3NAM0, H*RU:sk:BN3NAM0 X-HELO: NAM01-BN3-obe.outbound.protection.outlook.com Received: from mail-oln040092000083.outbound.protection.outlook.com (HELO NAM01-BN3-obe.outbound.protection.outlook.com) (40.92.0.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Mar 2018 02:33:43 +0000 Received: from BN3NAM01FT012.eop-nam01.prod.protection.outlook.com (10.152.66.52) by BN3NAM01HT117.eop-nam01.prod.protection.outlook.com (10.152.66.238) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.527.18; Fri, 9 Mar 2018 02:33:40 +0000 Received: from DM5PR16MB0059.namprd16.prod.outlook.com (10.152.66.54) by BN3NAM01FT012.mail.protection.outlook.com (10.152.67.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.527.18 via Frontend Transport; Fri, 9 Mar 2018 02:33:40 +0000 Received: from DM5PR16MB0059.namprd16.prod.outlook.com ([fe80::9bb:2ec1:14ee:bdae]) by DM5PR16MB0059.namprd16.prod.outlook.com ([fe80::9bb:2ec1:14ee:bdae%17]) with mapi id 15.20.0548.016; Fri, 9 Mar 2018 02:33:40 +0000 From: Fis Trivial To: "gcc@gcc.gnu.org" Subject: Compiling c++ template is very slow. Date: Fri, 09 Mar 2018 02:33:00 -0000 Message-ID: x-incomingtopheadermarker: OriginalChecksum:C1696B4B804403979A19141A1824B85D73975B6D85ED8B8237212C4DF413F8FD;UpperCasedChecksum:9EAC545C2DC74E7B88E3BEB1223C1403A5DEF7FD0F4E1CB7F897EF65E2C8F7EF;SizeAsReceived:6855;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [ipcQPe40VdI13dkxGNvKBL19UQMb7JZd] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BN3NAM01HT117;6:r3yWiyliXXAxA4cw+4IWjilvLR1ebi1hW5GzHDY2qP0Sw+REfSup89VGlRc8K4X9PSXRAi9Jm74kDmqIjFuTUAR8kKhEpgzMRyLBJwPCMl0nZNRDnBhSr9II8/YsKGtJeo5sbMpNTka3RQudzVrOva0jGtH8khNm00Ma+ZWSzAZonxEU60a8kh51OHpom/EXp3KlGLVG6cJ6i5KsNXW5ysCuYtBmY0EdJCEqPX9fkS2jE4K05R0EeiVNlWtZ0ft1ZPqSeka/66btWOdq1VzGUm8YyV2xeLJq/JTN6yT4X+Xttmgg1B3jXeDN4UvvzqHJ87THLtAI/8/VxCmL6WrY4IORoKVp2YO0xT0ajBrNOx8=;5:3pA+C0g24Lq7wx+Mxw7YPIbKpoub2p5O78pMAlI8MthL0uyPLlm4w7+x2uUWcg8w7KcpZGuU5puNh0cXK+UX4Y4zNybdx/XQBBSDJ03xSEuUh5cSATcLXZAorXd5s+qykID1WmvuE4um4Ug/sJ0iougdj8agM9Gl2afXIOWTKss=;24:RO/mtNGs0Q2m1n+FdNAvj6fWn9YVoN42SEvBwsdxdlyvffl5akjVUXhvWnao120AItCV0ePDsiRmYThknbZndNmCYvBmKaB9O8Yh20s1jh0=;7:0FFtRdGhbl2wuYdZ8ahCkXAgo0pXj2zAMx4jvJjcLZX0NPd9bOATEENtxA2aBYkIb2zRbWRsvD3Ad0SHXtgz/lbPweN4TS/zHPqf/8MCL+gEJHBpPDQf8UBjdTxUTTbpGZdgLTLnmgsQjqbwJyrMBDQUpFJfbiEo9Tq2O3tQNWqEoxIapB6WfMxLbZh6wVNXzHCn/yywojL8NX/K2qYUyOotQYeO00LQ/Vcd87AhRbbeTRseKpcC90F8sg7Q+7Id x-incomingheadercount: 44 x-eopattributedmessage: 0 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322404)(1601125374)(1603101448)(1701031045);SRVR:BN3NAM01HT117; x-ms-traffictypediagnostic: BN3NAM01HT117: x-ms-office365-filtering-correlation-id: 7bc7b46b-65e2-4b84-3b26-08d585662b41 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(444000031);SRVR:BN3NAM01HT117;BCL:0;PCL:0;RULEID:;SRVR:BN3NAM01HT117; x-forefront-prvs: 0606BBEB39 x-forefront-antispam-report: SFV:NSPM;SFS:(7070007)(98901004);DIR:OUT;SFP:1901;SCL:1;SRVR:BN3NAM01HT117;H:DM5PR16MB0059.namprd16.prod.outlook.com;FPR:;SPF:None;LANG:; x-microsoft-antispam-message-info: N4dm4a/8+Lh8sgJStBHvbHgk8xSZCDjLNhL40Hxy9HuSbqV35Bz6y+j2NYvKA8vW13Ex4+g2+CFFkVrWUrNM/p8rLXj17FgB0aaRL/U3Vu3kHwkowk/NVM2Lz+G7Q6TJWkcKGpmdgBoG8FCsGqxxLExMzYOIMhZk8iAU3VXHD0wthP/yO9f1RoDBSKUXQ1EL spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7bc7b46b-65e2-4b84-3b26-08d585662b41 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Mar 2018 02:33:40.7428 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3NAM01HT117 X-IsSubscribed: yes X-SW-Source: 2018-03/txt/msg00108.txt.bz2 I tried to use c++ template to generate code for a personal project, but found that the compilation time needed with g++ is much slower(exponentially) than with clang++. This is a code snippet for testing purpose: #include template struct v : v, v { static int constexpr m =3D a; static int constexpr n =3D b; static int constexpr s =3D a + b; }; template struct v<1, b> : v<1, b-1>=20 { static int constexpr m =3D 1; static int constexpr n =3D b; static int constexpr s =3D b + 1; }; template struct v : v { static int constexpr m =3D a; static int constexpr n =3D 1; static int constexpr s =3D a + 1; }; template <> struct v<1, 1> { static int constexpr m =3D 1; static int constexpr n =3D 1; static int constexpr s =3D 2; }; int main() { std::cout << v<7, 12>::s << std::endl; std::cout << v<4, 3>::s << std::endl; }; Here is the time information: --- $ time g++ -std=3Dc++11 generate.cc -o bygcc real 0m39.529s user 0m39.418s sys 0m0.053s $ time clang++ -std=3Dc++11 generate.cc -o byclang real 0m0.310s user 0m0.273s sys 0m0.024s --- When using greater value, gcc will require exponentially more time to compile while the needed time from clang grows linearly. For example, replacing the `main` function from above code to: int main() { // change 7 to 8 and drop <4, 3> std::cout << v<8, 12>::s << std::endl; }; --- $ time g++ -std=3Dc++11 generate.cc -o bygcc real 5m20.755s user 5m8.509s sys 0m0.260s $ time clang++ -std=3Dc++11 generate.cc -o byclang real 0m0.314s user 0m0.281s sys 0m0.020s --- Just for fun, making the template parameter to 128: --- $ time g++ -std=3Dc++11 generate.cc -o bygcc ... not gonna happen :). $ time clang++ -std=3Dc++11 generate.cc -o byclang real 0m18.549s user 0m18.410s sys 0m0.066s --- I am currently running Fedora 27 with following version of gcc and clang: $ g++ --version g++ (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5) Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ clang++ --version clang version 5.0.1 (tags/RELEASE_501/final) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/bin