# Could Clang displace GCC generally? Part II: Performance of PostgreSQL binaries

DevFeed: [Could Clang displace GCC generally? Part II: Performance of PostgreSQL binaries](<https://devfeed.tech/articles/could-clang-displace-gcc-generally-part-ii-performance-of-postgresql-binaries-33639.md>)

Original publisher: [Read original article](<https://pgeoghegan.blogspot.com/2011/07/could-clang-displace-gcc-generally-part.html>)

Author: Peter Geoghegan (noreply@blogger.com)

Published: 2011-07-28T16:12:00Z

Content type: article

Language: en

Sources: [Peter Geoghegan's blog](<https://devfeed.tech/sources/peter-geoghegan-s-blog.md>)

Topics: [clang](<https://devfeed.tech/topics/clang.md>), [gcc](<https://devfeed.tech/topics/gcc.md>), [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Benchmark](<https://devfeed.tech/topics/benchmark.md>), [cpu](<https://devfeed.tech/topics/cpu.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [benchmark](<https://devfeed.tech/tags/benchmark.md>), [c](<https://devfeed.tech/tags/c.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [clang](<https://devfeed.tech/tags/clang.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>)

## AI overview

This second article in a two-part series compares the performance of PostgreSQL binaries built with Clang and GCC. It uses repeated pgbench runs with identical compiler flags, four connections, and a CPU-focused workload to examine the difference between the two compilers.

## Source excerpt

This is the second in a two-part series on Clang. If you haven't already, you'll want to read my original post on the topic, Could Clang displace GCC among PostgreSQL developers? Part I: Intro and compile times. So, what about the performance of PostgreSQL binaries themselves when built with each compiler? I had heard contradictory reports of the performance of binaries built with Clang. In Belgium, Chris Lattner said that Clang built binaries could perform better, but a number of independent benchmarks suggested that Clang was generally behind, with some notable exceptions. I asked 2ndQuadrant colleague and PostgreSQL performance expert Greg Smith to suggest a useful benchmark to serve as a good starting point for comparing Postgres performance when built with Clang to performance when built with GCC. He suggested that I apply Jeff Janes' recent patch for pgbench that he'd reviewed. It stresses the executor, and therefore the CPU quite effectively, rather than table locks or IPC mechanisms. The results of this benchmark were very interesting. Greg provided me with shell access to a beefy server, the same server that he used in his review of Jeff's patch, which added the -P option: http://archives.postgresql.org/message-id/4DFE788F.5020704@2ndQuadrant.com . I hacked together a shell script to run pgbench for this purpose. Binaries were built using GCC and Clang, each with exactly the same flags - Clang accepts the same flags as GCC. To smooth the results out, and to get a conclusive outcome, I decided on 16 10 minute -P runs with 4 connections, that alternated between using each set of binaries, lasting a total of 3 hours. Here's a summary of the results: 1) GCC test: tps = 34.242839 (including connections establishing) 2) Clang test: tps = 34.370732 (including connections establishing) 3) GCC test: tps = 34.186687 (including connections establishing) 4) Clang test: tps = 34.922954 (including connections establishing) 5) GCC test: tps = 32.393383 (including connecti