[OE-core] [PATCH v2 09/12] udev-cache: get system config immediately before cache

Richard Tollerton rich.tollerton at ni.com
Mon Aug 25 18:20:00 UTC 2014


Richard Purdie <richard.purdie at linuxfoundation.org> writes:

> The above reason c) is also why we don't use cmp. It turned out to be
> faster to read into a variable than fork/exec cmp.

You appear to be wrong: cat+cmp is 27-41% faster than readfiles. In
fact, testing cat alone (without cmp) shows that `cat` to tmpfs file is
2x-3x as fast as readfiles.

These figures reproduce on both a Xilinx Zynq Cortex-A9 and my Xeon dev
machine; the former running busybox sh, the latter running bash.

See below for test script.

---

#!/bin/busybox sh

files="/proc/version /proc/cmdline /proc/devices"
runs=100

readfiles () {
   READDATA=""
   for filename in $@; do
	   if [ -r $filename ]; then
		   while read line; do
			   READDATA="$READDATA$line"
		   done < $filename
	   fi
   done
}

dotest_cat_inner () {
	cat $@
}

dotest_cat () {
	cat $@ > /tmp/a.txt
	cat $@ > /tmp/b.txt
	cmp /tmp/a.txt /tmp/b.txt
}

dotest_readfiles_inner () {
	readfiles $@
	echo "$READDATA"
}

dotest_readfiles () {
	readfiles $@
	NEWDATA="$READDATA"
	readfiles $@
	OLDDATA="$OLDDATA"
	[ "$OLDDATA" = "$NEWDATA" ]
}

timetest () {
	cmd=$1
	i=$2
	shift 2
	while [ "$i" -gt 0 ]; do
		$cmd $@ >/dev/null
		i=$(( i-1 ))
	done
}

case $1 in
cat) timetest dotest_cat $runs $files ;;
readfiles) timetest dotest_readfiles $runs $files ;;
inner_cat) timetest dotest_cat_inner $runs $files ;;
inner_readfiles) timetest dotest_readfiles_inner $runs $files ;;
*) 
	printf 'cat:\n'
	time $0 cat

	printf '\nreadfiles:\n'
	time $0 readfiles

	printf '\ncat_inner:\n'
	time $0 inner_cat

	printf '\nreadfiles_inner:\n'
	time $0 inner_readfiles
	;;
esac


> Cheers,
>
> Richard
>

-- 
Richard Tollerton <rich.tollerton at ni.com>



More information about the Openembedded-core mailing list