News for hackers. Stuff that matters.
Re:Ask HN: What is your go to performance optimization? by signa11 on Thursday July 25, 2024 @09:21AM (#41068372)
umm this is kinda tongue-in-cheek

```

#include <time.h>

#include <stdio.h>

int main(int argc, char argv[]) { int i = 0; time_t timep;

        /*
         * ok so now we are printing something
        **/
        printf("Greetings!\n");

        /*
         * this is a for loop from 0..9
        **/
        for(i=0; i<10; i++) {
                time(&timep);
                localtime(&timep);
        }

        printf("Godspeed, dear friend!\n");
        return 0;
}

```

now, the canonical

```

$> gcc tz-test.c -o obj/tz-test

```

now do this

```

$> unset TZ

$> strace -ff ./obj/tz-test 2>&1 | grep 'local' | wc

     10      77     851
$> export TZ=:/etc/localtime

$> strace -ff ./obj/tz-test 2>&1 | grep 'local' | wc

      1       5      59

```

moral, always set TZ to avoid localtime(3) from stat'ing /etc/localtime :o)

Re:Ask HN: What is your go to performance optimization? by perfsea on Thursday July 25, 2024 @10:54AM (#41069424)
lol never knew about this thanks. Has this actually slowed down someone's code?