Well, here's a beginning. This code can count invocations of operators.
%!
/logdict 1 dict def
/countname { %name
logdict 1 index known {
logdict exch
logdict 1 index get
1 add put
}{
logdict exch 1 put
} ifelse
} bind def
/logname { %name
logdict 1 index 0 put
[ 1 index /countname cvx 1 index load
dup xcheck 1 index type /arraytype eq and
{ /exec cvx } if
] cvx def
} bind def
1 dict begin
/add logname
/sub logname
/mul logname
/div logname
0 [ 0 1 20{}for ] { add } forall
[ 1 1 5{}for ] { mul } forall
[ 23 -2 4{}for ] { sub } forall
1 1 add
div =
logdict { exch =only( )=only == } forall
%eof
Output:
GPL Ghostscript 9.06 (2012-08-08)
Copyright (C) 2012 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
12530.0
add 22
sub 10
mul 5
div 1
GS>