Skip to content

and the winner is...

Ah, benchmarks - what else would we spend our CPU cycles on anyway? Quite a long time ago I was surprised to see that awk was so much slower than grep. This was a long time ago and I don't remember all the details, but there was sort involved too, and it was GNU/grep vs. Solaris/awk, IIRC. Anyway, here's what I did just now:
# ls -lhgo du.all; wc -l du.all 
 -rw-r--r--    1     2.2M Jan  7 17:26 du.all
          23773 du.all

# time sort -n du.all | grep -v /home > /dev/null 
real	0m8.939s
user	0m8.920s
sys	0m0.010s

# time grep -v /home du.all | sort -n > /dev/null 
real	0m25.694s
user	0m25.670s
sys	0m0.010s

# time awk '!/\/home/' du.all | sort -n > /dev/null 
real	0m0.622s
user	0m0.620s
sys	0m0.010s
Yes, the sort(1) is not even relvant here, it's really grep(1) taking so long. There's a --mmap switch to grep, promising better performance and sometimes coredumps, neither of both happened. This was done with GNU sort-4.5.3, GNU Awk 3.1.1, GNU grep 2.5.1. Oh, yeah - these may have been "current" versions back in ~2002 :)

How to disable Spotlight, Leopard style

There's a howto disable Spotlight for OS 10.4; for OS 10.5 it's a a bit different, as /etc/hostconfig is about to go away. In short:
$ sudo launchctl unload /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

To disable it permanently, type this instead:
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

To enable Spotlight type the following and press Return:
$ sudo launchctl load /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

To enable it permanently, type this instead:
$ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
Someone else suggested to disable even more:
$ sudo launchctl unload -w /System/Library/LaunchAgents/com.apple.Spotlight.plist
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
Hm, doing all that makes Spotlight stop indexing, but it's still running, and it respawns upon kill(1)....

Mit Windows waer das nicht passiert

Uh, Solaris, you stubborn beast:
$ date +%s
%s
No, implementing yet another switch to display a timestamp in seconds since epoch like the GNU or BSD tools do, would be too easy, now would it? Someone on the net even suggested this hack, which is kinda cool, but it still hurts my eyes so badly:
$ truss date 2>&1 | awk '/^time\(\)/ {print $3}'
1226293860
Maybe I should just go with:
$ perl -e "print time"
1226293869
....but having this one in date(1) would be nice too. Really.

Update: Malte wants to share his strace solution as well:
$ strace date 2>&1 | awk '/^clock_gettime/ {print $2}' | sed 's/[\{,]//g'

Update #2:
$ strace -ttt /bin/true 2>&1 | cut -d\. -f1 | head -1
1250491303
:-)