Write 200 blocks of 512k to a dummy file with dd, timing the result. The is useful as a quick test to compare the performance of different file systems.

by David Winterbottom (codeinthehole.com)

]]>by David Winterbottom (codeinthehole.com)

]]>This uses curl to find out the access times of a web service

by David Winterbottom (codeinthehole.com)

]]>Outputs the real time it takes a Redis ping to run in thousands of a second without any proceeding 0's. Useful for logging or scripted action.

by David Winterbottom (codeinthehole.com)

]]>Using tail to follow and standard perl to count and print the lps when lines are written to the logfile.

by David Winterbottom (codeinthehole.com)

]]>I've had a horrible time trying to pipe the output of some shell built-ins like 'time' to other programs. The built-in doesn't output to stdout or stderr most of the time but using the above will let you pipe the output to something else.

by David Winterbottom (codeinthehole.com)

]]>This one-liner is for cron jobs that need to provide some basic information about a filesystem and the time it takes to complete the operation. You can swap out the di command for df or du if that's your thing. The |& redirections the stderr and stdout to the mail command.

How to configure the variables.

TOFSCK=/path/to/mount

FSCKDEV=/dev/path/device

or

FSCKDEV=`grep $TOFSCK /proc/mounts | cut -f1 -d" "`

MAILSUB="weekly file system check $TOFSCK "

by David Winterbottom (codeinthehole.com)

]]>Say you want to time how long a task you're performing takes. Start this simple timer and you're done!

by David Winterbottom (codeinthehole.com)

]]>by David Winterbottom (codeinthehole.com)

]]>in loop, until the last port (65535), list all opened ports on host.

in the sample I used localhost, but you can replace with any host to test.

by David Winterbottom (codeinthehole.com)

]]>by David Winterbottom (codeinthehole.com)

]]>by David Winterbottom (codeinthehole.com)

]]>by David Winterbottom (codeinthehole.com)

]]>EDIT: Trolling crap removed ;)

takes approx 6 secs on a Core 2 Duo @ 2GHz, and 15 secs on atom based netbooks!

uses monoid (a,b).(x,y)=(ax+bx+ay,ax+by) with identity (0,1), and recursion relations:

F(2n-1)=Fn*Fn+F(n-1)*F(n-1)

F(2n)=(Fn+2*F(n-1))*Fn

then apply fast exponentiation to (1,0)^n = (Fn,F(n-1))

.

Note that: (1,0)^-1=(1,-1) so (a,b).(1,0) = (a+b,a) and (a,b)/(1,0)=(a,b).(1,0)^-1=(b,a-b)

So we can also use a NAF representation to do the exponentiation,http://en.wikipedia.org/wiki/Non-adjacent_form , it's also very fast (about the same, depends on n):

`time echo 'n=1000000;m=(n+1)/2;a=0;b=1;i=0;while(m>0){z=0;if(m%2)z=2-(m%4);m=(m-z)/2;e[i++]=z};while(i--){c=a*a;a=c+2*a*b;b=c+b*b;if(e[i]>0){t=a;a+=b;b=t};if(e[i]<0){t=a;a=b;b=t-b}};if(n%2)a*a+b*b;if(!n%2)a*(a+2*b)' | bc`

by David Winterbottom (codeinthehole.com)

]]>Calculates nth Fibonacci number for all n>=0, (much faster than matrix power algorithm from http://everything2.com/title/Compute+Fibonacci+numbers+FAST%2521 )

n=70332 is the biggest value at http://bigprimes.net/archive/fibonacci/ (corresponds to n=70331 there), this calculates it in less than a second, even on a netbook.

UPDATE: Now even faster! Uses recurrence relation for F(2n), see http://en.wikipedia.org/wiki/Fibonacci_number#Matrix_form

n is now adjusted to match Fn at wikipedia, so bigprimes.net table is offset by 1.

UPDATE2: Probably fastest possible now ;), uses a simple monoid operation:

uses monoid (a,b).(x,y)=(ax+bx+ay,ax+by) with identity (0,1), and recursion relations:

F(2n-1)=Fn*Fn+F(n-1)*F(n-1)

F(2n)=Fn*(2*F(n-1)+Fn)

then apply fast exponentiation to (1,0)^n = (Fn,F(n-1))

.

Note that: (1,0)^-1=(1,-1) so (a,b).(1,0) = (a+b,a) and (a,b)/(1,0)=(a,b).(1,0)^-1=(b,a-b)

So we can also use a NAF representation to do the exponentiation,http://en.wikipedia.org/wiki/Non-adjacent_form , it's also very fast (about the same, depends on n):

`time echo 'n=70332;m=(n+1)/2;a=0;b=1;i=0;while(m>0){z=0;if(m%2)z=2-(m%4);m=(m-z)/2;e[i++]=z};while(i--){c=a*a;a=c+2*a*b;b=c+b*b;if(e[i]>0){t=a;a+=b;b=t};if(e[i]<0){t=a;a=b;b=t-b}};if(n%2)a*a+b*b;if(!n%2)a*(a+2*b)' | bc`

by David Winterbottom (codeinthehole.com)

]]>Let dd use direct I/O to write directly to the disk without any caching. You'll encounter very different results with different block sizes (try with 1k, 4k, 1M, ... and appropriate count values).

by David Winterbottom (codeinthehole.com)

]]>Depending on the speed of you system, amount of RAM, and amount of free disk space, you can find out practically how fast your disks really are. When it completes, take the number of MB copied, and divide by the line showing the "real" number of seconds. In the sample output, the cached value shows a write speed of 178MB/s, which is unrealistic, while the calculated value using the output and the number of seconds shows it to be more like 35MB/s, which is feasible.

by David Winterbottom (codeinthehole.com)

]]>by David Winterbottom (codeinthehole.com)

]]>time read -sn1 (s:silent, n:number of characters. Press any character to stop)

by David Winterbottom (codeinthehole.com)

]]>I had a hard time in finding the correct settings to get reasonable output from a coin selector which sends its data over a serial line. In the end, minicom came to the rescue and pointed me on the right track.

So, if you need to do something similar, these settings may help you.

Replace ttyUSB0 with your device file, 9600 with your baud rate, 5 with your read timeout (10ths of a second), and 1 with the minimum numbers of characters you want to read.

You can then open the device file like you are used to do, example:

`DATA="`xxd -ps -l 5 \"$DEV\"`"`

by David Winterbottom (codeinthehole.com)

]]>Old snapshots can cause problems. It's best to remove them when finished. I use this script to remove all snapshots. The "while read" command is necessary because my vm names contain spaces. The "time" command reports how long the process runs.

by David Winterbottom (codeinthehole.com)

]]>The last ; is important. example:

time { rm -rf /folder/bar && mkdir -p /folder/bar ; echo "done" ; }

command is a bash builtin

by David Winterbottom (codeinthehole.com)

]]>This is a quick and dirty way to generate a (non-floating-point) CPU-bound task to benchmark. Adjust "20" to higher or lower values, as needed. As a benchmark this is probably a little less bogus than bogomips, and it will run anywhere 'bc' does.

by David Winterbottom (codeinthehole.com)

]]>