Skip to content

Instantly share code, notes, and snippets.

@simonhf
Last active July 26, 2019 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonhf/8e0a8def5b8612f826d56f0480a2ef70 to your computer and use it in GitHub Desktop.
Save simonhf/8e0a8def5b8612f826d56f0480a2ef70 to your computer and use it in GitHub Desktop.
C vs Golang in the context of run time performance considering compile time optimization ability with constant folding for debugging

Let's say you know C and are thinking about learning Golang. Let's also say that you prefer not to use a debugger [1]. This probably means you need to create a debug version of your Golang code. A way to do that is with constant folding [2], for example:

const constDebug = 0

if (1 == constDebug) { debugCode() } // if() compiled away due to constant folding

var localDebug uint64 = 0

if (1 == localDebug) { debugCode() } // if() NOT compiled away due to no constant

Using constant folding you can add an arbitrary amount of permanent debug instrumentation to your code without bloating or slowing down the release version of the code.

Some languages have constant folding and some don't. For example C has a kind of constant folding via its preprocessor. Perl has constant folding, but PHP has no constant folding. Golang does have constant folding but how to set a constant at compile time in order to create a release or debug version of the code? This is tricky with Golang but it can be done via command line tags [3].

Okay, so we have a way to build a release and debug version of code in both C and Golang. Let's create some tests to compare performance. Let's compare the performance of release vs debug versions of the code in each language. Let's compare the different compilers for C, e.g. gcc vs clang. Let's compare the affect of using local vs global variables, which might be treated differently by the optimizer? Let's compare the effect of constant folding even in the release version, e.g. similar to switching on and off custom functionality at compile time. Let's compare the cost of inline vs function debug code in Golang, for example:

if (1 == constDebug) { debugFunc() } // uglier debug inline

debugFunc() // nicer debug function

In the Golang release version then how will an empty function affect performance, for example:

func debugFunc() {
    // nothing here in Golang release version
}

The code in this gist contains such tests implemented in both C and Golang. Each variation consists of a loop with small variations of if()s and business logic. The loop iteration count is larger because it's easier and more meaningful to time the entire loop than an individual iteration inside the loop. Results on a Dell laptop with Xeon CPU are also included, togther with the results graphed.

Observations in general:

  • Using global variables appears to be generally slower than using local variables, regardless of the language or compiler.

Observations on C with gcc:

  • Naively, we would expect the local variable release versions to be ranked from fastest to slowest as CONST_FALSE, CONST_TRUE, local_var_false, local_var_true due to increasing amount of code executed.
  • However, the local variable release versions actual results ranked from fastest to slowest were local_var_true, CONST_TRUE, local_var_false, CONST_FALSE.
  • Interestingly, local_var_true is predicted as being the slowest but ends up as being by far the fastest, even though the code is exectuing at extra if() and an extra increment.
  • A couple of the compiled debug variants are mysteriously twice as slow as other variants, suggesting gcc optimization bugs?
  • These results make clear that even only considering the gcc, it's difficult to make assumptions that the compiler optimizer is doing a good job.

Observations on C with gcc vs C with clang:

  • None of the clang compiled variations approached the speed of the fastest gcc compiled variation.
  • The global variable clang compiled variations are significantly slower than the same gcc compiled variations.
  • Except for the release global varible variations, the obviously buggy gcc debug variations, and the extremely fast local_var_true gcc release variation, clang offers a competitive alternative to gcc.

Observations on Golang:

  • Using global variables in Golang can slow down the code by 2 to 3 times.
  • In the release version, half the time inline debug is faster, and half the time function debug is faster.
  • In the debug version with local variables, function debug is around twice as slow as inline debug.

Observations on Golang vs C:

  • Golang compile times were typically at least three times longer than using either C compiler.
  • For release variations with debug inline compiled away then Golang can be anywhere between 40% and 388% slower than C, and 248% slower on average based upon the 8 release code variations.
  • For release variations with debug functions compiled away then Golang can be anywhere between 5% and 397% slower than C, and 212% slower on average based upon the 8 release code variations.
  • Because both C and Golang compilers optimize unpredictably then its very difficult to determine whether tiny code tweaks in either language could result in performance gold.

[1] https://lemire.me/blog/2016/06/21/i-do-not-use-a-debugger/ [2] https://en.wikipedia.org/wiki/Constant_folding [3] https://dave.cheney.net/2013/10/12/how-to-use-conditional-compilation-with-the-go-build-tool

// +build debugoff
package main
const constDebug = 0
func debugFunc(n uint64, what * string) {
}
// +build debugon
package main
import "fmt"
const constDebug = 1
func debugFunc(n uint64, what * string) {
if (0 == n) { loopDebugString = fmt.Sprintf(" // inside loop %s", * what) }
}
#include <stdio.h>
#include <stdint.h>
#include <sys/time.h>
#include <time.h>
// gcc --version | egrep gcc ; echo "compile time:" ; time gcc -O2 -DCONST_DEBUG=0 -o main main.c ; ./main
// gcc --version | egrep gcc ; echo "compile time:" ; time gcc -O2 -DCONST_DEBUG=1 -o main main.c ; ./main
// clang --version | egrep clang ; echo "compile time:" ; time clang -O2 -DCONST_DEBUG=0 -o main main.c ; ./main
// clang --version | egrep clang ; echo "compile time:" ; time clang -O2 -DCONST_DEBUG=1 -o main main.c ; ./main
#define CONST_FALSE (0)
#define CONST_TRUE (1)
#define LOOPS (500000000)
char what[4096];
char loop_debug_string[4096];
uint64_t global_n;
uint64_t global_count_odd;
uint64_t global_count_even;
uint64_t global_cond_count;
uint64_t global_var_false = 0;
uint64_t global_var_true = 1;
double get_time_in_seconds(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return (double)tv.tv_sec + 1.e-6 * (double)tv.tv_usec;
}
int main(void) {
snprintf(loop_debug_string, sizeof(loop_debug_string), "%s", "");
double start;
double ms;
uint64_t local_n;
uint64_t local_count_odd;
uint64_t local_count_even;
uint64_t local_cond_count;
uint64_t local_var_false = 0;
uint64_t local_var_true = 1;
snprintf(what, sizeof(what), "%-16s with %6s vars and %-14s", "CONST_FALSE", "local", "debug inline"); local_count_odd = 0; local_count_even = 0; start = get_time_in_seconds();
for(local_n = 0; local_n < LOOPS; local_n++) {
if (1 == (local_n & 1)) { local_count_odd ++; } else {
#if 1 == CONST_FALSE
local_count_even ++;
#endif
}
#if 1 == CONST_DEBUG
if (0 == local_n) { snprintf(loop_debug_string, sizeof(loop_debug_string), " // inside loop %s", what); }
#endif
}
ms = (get_time_in_seconds() - start) * 1000;
printf("c: %9lu=local_count_odd %9lu=local_count_even in %11.6f ms <-- using loop %s%s\n", local_count_odd, local_count_even, ms, what, loop_debug_string);
snprintf(what, sizeof(what), "%-16s with %6s vars and %-14s", "CONST_TRUE", "local", "debug inline"); local_count_odd = 0; local_count_even = 0; start = get_time_in_seconds();
for(local_n = 0; local_n < LOOPS; local_n++) {
if (1 == (local_n & 1)) { local_count_odd ++; } else {
#if 1 == CONST_TRUE
local_count_even ++;
#endif
}
#if 1 == CONST_DEBUG
if (0 == local_n) { snprintf(loop_debug_string, sizeof(loop_debug_string), " // inside loop %s", what); }
#endif
}
ms = (get_time_in_seconds() - start) * 1000;
printf("c: %9lu=local_count_odd %9lu=local_count_even in %11.6f ms <-- using loop %s%s\n", local_count_odd, local_count_even, ms, what, loop_debug_string);
snprintf(what, sizeof(what), "%-16s with %6s vars and %-14s", "local_var_false", "local", "debug inline"); local_count_odd = 0; local_count_even = 0; start = get_time_in_seconds();
for(local_n = 0; local_n < LOOPS; local_n++) {
if (1 == (local_n & 1)) { local_count_odd ++; } else {
if (1 == local_var_false) { local_count_even ++; }
}
#if 1 == CONST_DEBUG
if (0 == local_n) { snprintf(loop_debug_string, sizeof(loop_debug_string), " // inside loop %s", what); }
#endif
}
ms = (get_time_in_seconds() - start) * 1000;
printf("c: %9lu=local_count_odd %9lu=local_count_even in %11.6f ms <-- using loop %s%s\n", local_count_odd, local_count_even, ms, what, loop_debug_string);
snprintf(what, sizeof(what), "%-16s with %6s vars and %-14s", "local_var_true", "local", "debug inline"); local_count_odd = 0; local_count_even = 0; start = get_time_in_seconds();
for(local_n = 0; local_n < LOOPS; local_n++) {
if (1 == (local_n & 1)) { local_count_odd ++; } else {
if (1 == local_var_true) { local_count_even ++; }
}
#if 1 == CONST_DEBUG
if (0 == local_n) { snprintf(loop_debug_string, sizeof(loop_debug_string), " // inside loop %s", what); }
#endif
}
ms = (get_time_in_seconds() - start) * 1000;
printf("c: %9lu=local_count_odd %9lu=local_count_even in %11.6f ms <-- using loop %s%s\n\n", local_count_odd, local_count_even, ms, what, loop_debug_string);
snprintf(what, sizeof(what), "%-16s with %6s vars and %-14s", "CONST_FALSE", "global", "debug inline"); global_count_odd = 0; global_count_even = 0; start = get_time_in_seconds();
for(global_n = 0; global_n < LOOPS; global_n++) {
if (1 == (global_n & 1)) { global_count_odd ++; } else {
#if 1 == CONST_FALSE
global_count_even ++;
#endif
}
#if 1 == CONST_DEBUG
if (0 == global_n) { snprintf(loop_debug_string, sizeof(loop_debug_string), " // inside loop %s", what); }
#endif
}
ms = (get_time_in_seconds() - start) * 1000;
printf("c: %9lu=global_count_odd %9lu=global_count_even in %11.6f ms <-- using loop %s%s\n", global_count_odd, global_count_even, ms, what, loop_debug_string);
snprintf(what, sizeof(what), "%-16s with %6s vars and %-14s", "CONST_TRUE", "global", "debug inline"); global_count_odd = 0; global_count_even = 0; start = get_time_in_seconds();
for(global_n = 0; global_n < LOOPS; global_n++) {
if (1 == (global_n & 1)) { global_count_odd ++; } else {
#if 1 == CONST_TRUE
global_count_even ++;
#endif
}
#if 1 == CONST_DEBUG
if (0 == global_n) { snprintf(loop_debug_string, sizeof(loop_debug_string), " // inside loop %s", what); }
#endif
}
ms = (get_time_in_seconds() - start) * 1000;
printf("c: %9lu=global_count_odd %9lu=global_count_even in %11.6f ms <-- using loop %s%s\n", global_count_odd, global_count_even, ms, what, loop_debug_string);
snprintf(what, sizeof(what), "%-16s with %6s vars and %-14s", "global_var_false", "global", "debug inline"); global_count_odd = 0; global_count_even = 0; start = get_time_in_seconds();
for(global_n = 0; global_n < LOOPS; global_n++) {
if (1 == (global_n & 1)) { global_count_odd ++; } else {
if (1 == global_var_false) { global_count_even ++; }
}
#if 1 == CONST_DEBUG
if (0 == global_n) { snprintf(loop_debug_string, sizeof(loop_debug_string), " // inside loop %s", what); }
#endif
}
ms = (get_time_in_seconds() - start) * 1000;
printf("c: %9lu=global_count_odd %9lu=global_count_even in %11.6f ms <-- using loop %s%s\n", global_count_odd, global_count_even, ms, what, loop_debug_string);
snprintf(what, sizeof(what), "%-16s with %6s vars and %-14s", "global_var_true", "global", "debug inline"); global_count_odd = 0; global_count_even = 0; start = get_time_in_seconds();
for(global_n = 0; global_n < LOOPS; global_n++) {
if (1 == (global_n & 1)) { global_count_odd ++; } else {
if (1 == global_var_true) { global_count_even ++; }
}
#if 1 == CONST_DEBUG
if (0 == global_n) { snprintf(loop_debug_string, sizeof(loop_debug_string), " // inside loop %s", what); }
#endif
}
ms = (get_time_in_seconds() - start) * 1000;
printf("c: %9lu=global_count_odd %9lu=global_count_even in %11.6f ms <-- using loop %s%s\n\n", global_count_odd, global_count_even, ms, what, loop_debug_string);
} /* main() */
// https://stackoverflow.com/questions/36151298/is-there-a-way-to-define-a-constant-at-build-time-in-go
// https://dave.cheney.net/2013/10/12/how-to-use-conditional-compilation-with-the-go-build-tool
// https://golang.org/pkg/go/build/#hdr-Build_Constraints
// $ go version ; echo "compile time:" ; time go build -o main -tags debugon && ./main
// $ go version ; echo "compile time:" ; time go build -o main -tags debugoff && ./main
package main
import "fmt"
import "time"
var what = ""
var loopDebugString = ""
var globalVarFalse uint64 = 0
var globalVarTrue uint64 = 1
var globalN uint64
var globalCount uint64
var globalCountOdd uint64
var globalCountEven uint64
var globalCondCount uint64
const constFalse = 0
const constTrue = 1
const loops = 500000000
func main() {
var start time.Time
var localN uint64
var localCountOdd uint64
var localCountEven uint64
var localVarFalse uint64 = 0
var localVarTrue uint64 = 1
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "constFalse", "local", "debug inline"); localCountOdd = 0; localCountEven = 0; start = time.Now()
for localN = 0; localN < loops; localN++ {
if (1 == (localN & 1)) { localCountOdd ++ } else {
if (1 == constFalse) { localCountEven ++ }
}
if (1 == constDebug) { if (0 == localN) { loopDebugString = fmt.Sprintf(" // inside loop %s", what) } }
}
fmt.Printf("go: %9d=localCountOdd %9d=localCountEven in %11.6f ms <-- using loop %s%s\n", localCountOdd, localCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "constTrue", "local", "debug inline"); localCountOdd = 0; localCountEven = 0; start = time.Now()
for localN = 0; localN < loops; localN++ {
if (1 == (localN & 1)) { localCountOdd ++ } else {
if (1 == constTrue) { localCountEven ++ }
}
if (1 == constDebug) { if (0 == localN) { loopDebugString = fmt.Sprintf(" // inside loop %s", what) } }
}
fmt.Printf("go: %9d=localCountOdd %9d=localCountEven in %11.6f ms <-- using loop %s%s\n", localCountOdd, localCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "localVarFalse", "local", "debug inline"); localCountOdd = 0; localCountEven = 0; start = time.Now()
for localN = 0; localN < loops; localN++ {
if (1 == (localN & 1)) { localCountOdd ++ } else {
if (1 == localVarFalse) { localCountEven ++ }
}
if (1 == constDebug) { if (0 == localN) { loopDebugString = fmt.Sprintf(" // inside loop %s", what) } }
}
fmt.Printf("go: %9d=localCountOdd %9d=localCountEven in %11.6f ms <-- using loop %s%s\n", localCountOdd, localCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "localVarTrue", "local", "debug inline"); localCountOdd = 0; localCountEven = 0; start = time.Now()
for localN = 0; localN < loops; localN++ {
if (1 == (localN & 1)) { localCountOdd ++ } else {
if (1 == localVarTrue) { localCountEven ++ }
}
if (1 == constDebug) { if (0 == localN) { loopDebugString = fmt.Sprintf(" // inside loop %s", what) } }
}
fmt.Printf("go: %9d=localCountOdd %9d=localCountEven in %11.6f ms <-- using loop %s%s\n\n", localCountOdd, localCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "constFalse", "global", "debug inline"); globalCountOdd = 0; globalCountEven = 0; start = time.Now()
for globalN = 0; globalN < loops; globalN++ {
if (1 == (globalN & 1)) { globalCountOdd ++ } else {
if (1 == constFalse) { globalCountEven ++ }
}
if (1 == constDebug) { if (0 == globalN) { loopDebugString = fmt.Sprintf(" // inside loop %s", what) } }
}
fmt.Printf("go: %9d=globalCountOdd %9d=globalCountEven in %11.6f ms <-- using loop %s%s\n", globalCountOdd, globalCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "constTrue", "global", "debug inline"); globalCountOdd = 0; globalCountEven = 0; start = time.Now()
for globalN = 0; globalN < loops; globalN++ {
if (1 == (globalN & 1)) { globalCountOdd ++ } else {
if (1 == constTrue) { globalCountEven ++ }
}
if (1 == constDebug) { if (0 == globalN) { loopDebugString = fmt.Sprintf(" // inside loop %s", what) } }
}
fmt.Printf("go: %9d=globalCountOdd %9d=globalCountEven in %11.6f ms <-- using loop %s%s\n", globalCountOdd, globalCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "globalVarFalse", "global", "debug inline"); globalCountOdd = 0; globalCountEven = 0; start = time.Now()
for globalN = 0; globalN < loops; globalN++ {
if (1 == (globalN & 1)) { globalCountOdd ++ } else {
if (1 == globalVarFalse) { globalCountEven ++ }
}
if (1 == constDebug) { if (0 == globalN) { loopDebugString = fmt.Sprintf(" // inside loop %s", what) } }
}
fmt.Printf("go: %9d=globalCountOdd %9d=globalCountEven in %11.6f ms <-- using loop %s%s\n", globalCountOdd, globalCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "globalVarTrue", "global", "debug inline"); globalCountOdd = 0; globalCountEven = 0; start = time.Now()
for globalN = 0; globalN < loops; globalN++ {
if (1 == (globalN & 1)) { globalCountOdd ++ } else {
if (1 == globalVarTrue) { globalCountEven ++ }
}
if (1 == constDebug) { if (0 == globalN) { loopDebugString = fmt.Sprintf(" // inside loop %s", what) } }
}
fmt.Printf("go: %9d=globalCountOdd %9d=globalCountEven in %11.6f ms <-- using loop %s%s\n\n", globalCountOdd, globalCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "constFalse", "local", "debug function"); localCountOdd = 0; localCountEven = 0; start = time.Now()
for localN = 0; localN < loops; localN++ {
if (1 == (localN & 1)) { localCountOdd ++ } else {
if (1 == constFalse) { localCountEven ++ }
}
debugFunc(localN, &what)
}
fmt.Printf("go: %9d=localCountOdd %9d=localCountEven in %11.6f ms <-- using loop %s%s\n", localCountOdd, localCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "constTrue", "local", "debug function"); localCountOdd = 0; localCountEven = 0; start = time.Now()
for localN = 0; localN < loops; localN++ {
if (1 == (localN & 1)) { localCountOdd ++ } else {
if (1 == constTrue) { localCountEven ++ }
}
debugFunc(localN, &what)
}
fmt.Printf("go: %9d=localCountOdd %9d=localCountEven in %11.6f ms <-- using loop %s%s\n", localCountOdd, localCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "localVarFalse", "local", "debug function"); localCountOdd = 0; localCountEven = 0; start = time.Now()
for localN = 0; localN < loops; localN++ {
if (1 == (localN & 1)) { localCountOdd ++ } else {
if (1 == localVarFalse) { localCountEven ++ }
}
debugFunc(localN, &what)
}
fmt.Printf("go: %9d=localCountOdd %9d=localCountEven in %11.6f ms <-- using loop %s%s\n", localCountOdd, localCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "localVarTrue", "local", "debug function"); localCountOdd = 0; localCountEven = 0; start = time.Now()
for localN = 0; localN < loops; localN++ {
if (1 == (localN & 1)) { localCountOdd ++ } else {
if (1 == localVarTrue) { localCountEven ++ }
}
debugFunc(localN, &what)
}
fmt.Printf("go: %9d=localCountOdd %9d=localCountEven in %11.6f ms <-- using loop %s%s\n\n", localCountOdd, localCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "constFalse", "global", "debug function"); globalCountOdd = 0; globalCountEven = 0; start = time.Now()
for globalN = 0; globalN < loops; globalN++ {
if (1 == (globalN & 1)) { globalCountOdd ++ } else {
if (1 == constFalse) { globalCountEven ++ }
}
debugFunc(globalN, &what)
}
fmt.Printf("go: %9d=globalCountOdd %9d=globalCountEven in %11.6f ms <-- using loop %s%s\n", globalCountOdd, globalCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "constTrue", "global", "debug function"); globalCountOdd = 0; globalCountEven = 0; start = time.Now()
for globalN = 0; globalN < loops; globalN++ {
if (1 == (globalN & 1)) { globalCountOdd ++ } else {
if (1 == constTrue) { globalCountEven ++ }
}
debugFunc(globalN, &what)
}
fmt.Printf("go: %9d=globalCountOdd %9d=globalCountEven in %11.6f ms <-- using loop %s%s\n", globalCountOdd, globalCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "globalVarFalse", "global", "debug function"); globalCountOdd = 0; globalCountEven = 0; start = time.Now()
for globalN = 0; globalN < loops; globalN++ {
if (1 == (globalN & 1)) { globalCountOdd ++ } else {
if (1 == globalVarFalse) { globalCountEven ++ }
}
debugFunc(globalN, &what)
}
fmt.Printf("go: %9d=globalCountOdd %9d=globalCountEven in %11.6f ms <-- using loop %s%s\n", globalCountOdd, globalCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
what = fmt.Sprintf("%-14s with %6s vars and %-14s", "globalVarTrue", "global", "debug function"); globalCountOdd = 0; globalCountEven = 0; start = time.Now()
for globalN = 0; globalN < loops; globalN++ {
if (1 == (globalN & 1)) { globalCountOdd ++ } else {
if (1 == globalVarTrue) { globalCountEven ++ }
}
debugFunc(globalN, &what)
}
fmt.Printf("go: %9d=globalCountOdd %9d=globalCountEven in %11.6f ms <-- using loop %s%s\n\n", globalCountOdd, globalCountEven, time.Now().Sub(start).Seconds() * 1000, what, loopDebugString)
}
$ gcc --version | egrep gcc ; echo "compile time:" ; time gcc -O2 -DCONST_DEBUG=0 -o main main.c ; ./main
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
compile time:
real 0m0.093s
user 0m0.068s
sys 0m0.012s
c: 250000000=local_count_odd 0=local_count_even in 289.988995 ms <-- using loop CONST_FALSE with local vars and debug inline
c: 250000000=local_count_odd 250000000=local_count_even in 215.475082 ms <-- using loop CONST_TRUE with local vars and debug inline
c: 250000000=local_count_odd 0=local_count_even in 287.593126 ms <-- using loop local_var_false with local vars and debug inline
c: 250000000=local_count_odd 250000000=local_count_even in 144.699097 ms <-- using loop local_var_true with local vars and debug inline
c: 250000000=global_count_odd 0=global_count_even in 215.573072 ms <-- using loop CONST_FALSE with global vars and debug inline
c: 250000000=global_count_odd 250000000=global_count_even in 287.155151 ms <-- using loop CONST_TRUE with global vars and debug inline
c: 250000000=global_count_odd 0=global_count_even in 287.353992 ms <-- using loop global_var_false with global vars and debug inline
c: 250000000=global_count_odd 250000000=global_count_even in 287.403822 ms <-- using loop global_var_true with global vars and debug inline
$ gcc --version | egrep gcc ; echo "compile time:" ; time gcc -O2 -DCONST_DEBUG=1 -o main main.c ; ./main
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
compile time:
real 0m0.093s
user 0m0.064s
sys 0m0.016s
c: 250000000=local_count_odd 0=local_count_even in 575.561047 ms <-- using loop CONST_FALSE with local vars and debug inline // inside loop CONST_FALSE with local vars and debug inline
c: 250000000=local_count_odd 250000000=local_count_even in 298.391104 ms <-- using loop CONST_TRUE with local vars and debug inline // inside loop CONST_TRUE with local vars and debug inline
c: 250000000=local_count_odd 0=local_count_even in 244.988203 ms <-- using loop local_var_false with local vars and debug inline // inside loop local_var_false with local vars and debug inline
c: 250000000=local_count_odd 250000000=local_count_even in 573.210955 ms <-- using loop local_var_true with local vars and debug inline // inside loop local_var_true with local vars and debug inline
c: 250000000=global_count_odd 0=global_count_even in 659.428120 ms <-- using loop CONST_FALSE with global vars and debug inline // inside loop CONST_FALSE with global vars and debug inline
c: 250000000=global_count_odd 250000000=global_count_even in 690.763950 ms <-- using loop CONST_TRUE with global vars and debug inline // inside loop CONST_TRUE with global vars and debug inline
c: 250000000=global_count_odd 0=global_count_even in 698.734045 ms <-- using loop global_var_false with global vars and debug inline // inside loop global_var_false with global vars and debug inline
c: 250000000=global_count_odd 250000000=global_count_even in 700.286865 ms <-- using loop global_var_true with global vars and debug inline // inside loop global_var_true with global vars and debug inline
$ clang --version | egrep clang ; echo "compile time:" ; time clang -O2 -DCONST_DEBUG=0 -o main main.c ; ./main
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
compile time:
real 0m0.104s
user 0m0.060s
sys 0m0.036s
c: 250000000=local_count_odd 0=local_count_even in 259.092093 ms <-- using loop CONST_FALSE with local vars and debug inline
c: 250000000=local_count_odd 250000000=local_count_even in 299.911022 ms <-- using loop CONST_TRUE with local vars and debug inline
c: 250000000=local_count_odd 0=local_count_even in 265.083075 ms <-- using loop local_var_false with local vars and debug inline
c: 250000000=local_count_odd 250000000=local_count_even in 299.432993 ms <-- using loop local_var_true with local vars and debug inline
c: 250000000=global_count_odd 0=global_count_even in 389.431953 ms <-- using loop CONST_FALSE with global vars and debug inline
c: 250000000=global_count_odd 250000000=global_count_even in 397.378922 ms <-- using loop CONST_TRUE with global vars and debug inline
c: 250000000=global_count_odd 0=global_count_even in 391.566992 ms <-- using loop global_var_false with global vars and debug inline
c: 250000000=global_count_odd 250000000=global_count_even in 397.593975 ms <-- using loop global_var_true with global vars and debug inline
$ clang --version | egrep clang ; echo "compile time:" ; time clang -O2 -DCONST_DEBUG=1 -o main main.c ; ./main
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
compile time:
real 0m0.093s
user 0m0.056s
sys 0m0.032s
c: 250000000=local_count_odd 0=local_count_even in 290.049076 ms <-- using loop CONST_FALSE with local vars and debug inline // inside loop CONST_FALSE with local vars and debug inline
c: 250000000=local_count_odd 250000000=local_count_even in 366.957903 ms <-- using loop CONST_TRUE with local vars and debug inline // inside loop CONST_TRUE with local vars and debug inline
c: 250000000=local_count_odd 0=local_count_even in 286.732197 ms <-- using loop local_var_false with local vars and debug inline // inside loop local_var_false with local vars and debug inline
c: 250000000=local_count_odd 250000000=local_count_even in 367.547035 ms <-- using loop local_var_true with local vars and debug inline // inside loop local_var_true with local vars and debug inline
c: 250000000=global_count_odd 0=global_count_even in 629.445791 ms <-- using loop CONST_FALSE with global vars and debug inline // inside loop CONST_FALSE with global vars and debug inline
c: 250000000=global_count_odd 250000000=global_count_even in 835.504055 ms <-- using loop CONST_TRUE with global vars and debug inline // inside loop CONST_TRUE with global vars and debug inline
c: 250000000=global_count_odd 0=global_count_even in 702.033043 ms <-- using loop global_var_false with global vars and debug inline // inside loop global_var_false with global vars and debug inline
c: 250000000=global_count_odd 250000000=global_count_even in 760.470152 ms <-- using loop global_var_true with global vars and debug inline // inside loop global_var_true with global vars and debug inline
$ go version ; echo "compile time:" ; time go build -o main -tags debugoff && ./main
go version go1.6.2 linux/amd64
compile time:
real 0m0.330s
user 0m0.392s
sys 0m0.048s
go: 250000000=localCountOdd 0=localCountEven in 406.603668 ms <-- using loop constFalse with local vars and debug inline
go: 250000000=localCountOdd 250000000=localCountEven in 677.610302 ms <-- using loop constTrue with local vars and debug inline
go: 250000000=localCountOdd 0=localCountEven in 423.863366 ms <-- using loop localVarFalse with local vars and debug inline
go: 250000000=localCountOdd 250000000=localCountEven in 573.150663 ms <-- using loop localVarTrue with local vars and debug inline
go: 250000000=globalCountOdd 0=globalCountEven in 1049.887588 ms <-- using loop constFalse with global vars and debug inline
go: 250000000=globalCountOdd 250000000=globalCountEven in 1324.848583 ms <-- using loop constTrue with global vars and debug inline
go: 250000000=globalCountOdd 0=globalCountEven in 1352.738843 ms <-- using loop globalVarFalse with global vars and debug inline
go: 250000000=globalCountOdd 250000000=globalCountEven in 1037.595744 ms <-- using loop globalVarTrue with global vars and debug inline
go: 250000000=localCountOdd 0=localCountEven in 304.599407 ms <-- using loop constFalse with local vars and debug function
go: 250000000=localCountOdd 250000000=localCountEven in 560.179028 ms <-- using loop constTrue with local vars and debug function
go: 250000000=localCountOdd 0=localCountEven in 492.382246 ms <-- using loop localVarFalse with local vars and debug function
go: 250000000=localCountOdd 250000000=localCountEven in 413.594304 ms <-- using loop localVarTrue with local vars and debug function
go: 250000000=globalCountOdd 0=globalCountEven in 1068.154348 ms <-- using loop constFalse with global vars and debug function
go: 250000000=globalCountOdd 250000000=globalCountEven in 1152.354047 ms <-- using loop constTrue with global vars and debug function
go: 250000000=globalCountOdd 0=globalCountEven in 1113.453837 ms <-- using loop globalVarFalse with global vars and debug function
go: 250000000=globalCountOdd 250000000=globalCountEven in 1104.491668 ms <-- using loop globalVarTrue with global vars and debug function
$ go version ; echo "compile time:" ; time go build -o main -tags debugon && ./main
go version go1.6.2 linux/amd64
compile time:
real 0m0.356s
user 0m0.448s
sys 0m0.064s
go: 250000000=localCountOdd 0=localCountEven in 448.733185 ms <-- using loop constFalse with local vars and debug inline // inside loop constFalse with local vars and debug inline
go: 250000000=localCountOdd 250000000=localCountEven in 672.495735 ms <-- using loop constTrue with local vars and debug inline // inside loop constTrue with local vars and debug inline
go: 250000000=localCountOdd 0=localCountEven in 642.882571 ms <-- using loop localVarFalse with local vars and debug inline // inside loop localVarFalse with local vars and debug inline
go: 250000000=localCountOdd 250000000=localCountEven in 653.466500 ms <-- using loop localVarTrue with local vars and debug inline // inside loop localVarTrue with local vars and debug inline
go: 250000000=globalCountOdd 0=globalCountEven in 1328.536875 ms <-- using loop constFalse with global vars and debug inline // inside loop constFalse with global vars and debug inline
go: 250000000=globalCountOdd 250000000=globalCountEven in 1211.803045 ms <-- using loop constTrue with global vars and debug inline // inside loop constTrue with global vars and debug inline
go: 250000000=globalCountOdd 0=globalCountEven in 1170.223317 ms <-- using loop globalVarFalse with global vars and debug inline // inside loop globalVarFalse with global vars and debug inline
go: 250000000=globalCountOdd 250000000=globalCountEven in 814.031681 ms <-- using loop globalVarTrue with global vars and debug inline // inside loop globalVarTrue with global vars and debug inline
go: 250000000=localCountOdd 0=localCountEven in 1143.883513 ms <-- using loop constFalse with local vars and debug function // inside loop constFalse with local vars and debug function
go: 250000000=localCountOdd 250000000=localCountEven in 1261.488575 ms <-- using loop constTrue with local vars and debug function // inside loop constTrue with local vars and debug function
go: 250000000=localCountOdd 0=localCountEven in 1220.020152 ms <-- using loop localVarFalse with local vars and debug function // inside loop localVarFalse with local vars and debug function
go: 250000000=localCountOdd 250000000=localCountEven in 1123.283329 ms <-- using loop localVarTrue with local vars and debug function // inside loop localVarTrue with local vars and debug function
go: 250000000=globalCountOdd 0=globalCountEven in 1050.366767 ms <-- using loop constFalse with global vars and debug function // inside loop constFalse with global vars and debug function
go: 250000000=globalCountOdd 250000000=globalCountEven in 1226.453832 ms <-- using loop constTrue with global vars and debug function // inside loop constTrue with global vars and debug function
go: 250000000=globalCountOdd 0=globalCountEven in 1119.651658 ms <-- using loop globalVarFalse with global vars and debug function // inside loop globalVarFalse with global vars and debug function
go: 250000000=globalCountOdd 250000000=globalCountEven in 1279.088085 ms <-- using loop globalVarTrue with global vars and debug function // inside loop globalVarTrue with global vars and debug function
@simonhf
Copy link
Author

simonhf commented Jul 26, 2019

Screenshot from 2019-07-26 11-17-06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment