Skip to content

Instantly share code, notes, and snippets.

@jtanx
Last active September 15, 2018 01:44
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 jtanx/7b4aba7446e6d6372a8529f5b6fedab0 to your computer and use it in GitHub Desktop.
Save jtanx/7b4aba7446e6d6372a8529f5b6fedab0 to your computer and use it in GitHub Desktop.
log slowness

Windows

  • VS2015 x64: 10.19 sec: 3591342062.644168

  • mingw-w64 x64 gcc 7.3.0 (msys2): 29.3 sec: 3591342062.644168

  • VS2015 32-bit: 13.71 sec: 3591342062.644168

  • mingw-w64 32-bit gcc 7.3.0 (msys2): 27.23 sec: 3591342062.644168

  • windows go 1.8.3: 16.67 sec: 3591342062.644168

Linux/Virtualbox

  • Alpine/musl gcc 6.4.0: 47.62 sec: 3591342062.644168
  • Debian/glibc 2.24-11 gcc 6.3.0: 82.15 sec: 3591342062.644168
  • debian go 1.7.4: 21.66 sec: 3591342062.644168

ARM

  • RPi3/glibc 2.24-11 gcc 6.3.0: 204.3 sec: 3591342062.644168

Linux/Virtualbox - Docker (C)

  • alpine docker: 25.06 sec: 3591342062.644168
  • debian: 71.39 sec: 3591342062.644168

https://github.com/lattera/glibc/commit/b7c83ca30ef8e85b6642151d95600a36535f8d97

#include <stdio.h>
#include <math.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
struct timespec diff(struct timespec start, struct timespec end)
{
struct timespec temp;
if ((end.tv_nsec-start.tv_nsec)<0) {
temp.tv_sec = end.tv_sec-start.tv_sec-1;
temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
} else {
temp.tv_sec = end.tv_sec-start.tv_sec;
temp.tv_nsec = end.tv_nsec-start.tv_nsec;
}
return temp;
}
int main()
{
struct timespec start, end;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
double x = 0;
for (int j = 0; j < 10000000; j++)
{
for (int i = 1; i < 100; i++)
{
x += log(i);
}
}
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end);
struct timespec df = diff(start, end);
double fdf = df.tv_sec;
fdf += (df.tv_nsec / 1000000000.0);
printf("%.4g sec: %f\n", fdf, x);
}
#include <cstdio>
#include <cmath>
#include <chrono>
int main()
{
auto now = std::chrono::high_resolution_clock::now();
double x = 0;
for (int j = 0; j < 10000000; j++)
{
for (int i = 1; i < 100; i++)
{
//double a = std::exp(i);
x += std::log(i);
//i += std::exp(i);
}
}
std::chrono::duration<double> dur = std::chrono::high_resolution_clock::now() - now;
printf("%.4g sec: %f\n", dur.count(), x);
getchar();
}
package main
import (
"fmt"
"math"
"time"
)
func main() {
now := time.Now()
var x float64
for i := 0; i < 10000000; i++ {
for j := 1; j < 100; j++ {
x += math.Log(float64(j))
}
}
fmt.Printf("%.4g sec: %f\n", time.Since(now).Seconds(), x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment