diff options
-rw-r--r-- | AUTHORS | 2 | ||||
-rw-r--r-- | README | 32 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | bench.tcl | 59 | ||||
-rw-r--r-- | jim.h | 2 |
5 files changed, 91 insertions, 6 deletions
@@ -1,6 +1,6 @@ Salvatore Sanfilippo <antirez@invece.org> -with the help (patches, bug reports, ideas) of: +with the help (patches, bug reports, ideas, extensions) of: Pat Thoyts Clemens Hintze @@ -21,7 +21,7 @@ dual ported objects to ensure that the execution time does not reflect the semantic of the language :) ------------------------------------------------------------------------------ -WHERE JIM IS USEFUL? +WHEN JIM CAN BE USEFUL? ------------------------------------------------------------------------------ 1) If you are writing an application, and want to make it scriptable, with @@ -30,6 +30,11 @@ with a big system. You can just put jim.c and jim.h files in your project and use the Jim API to write the glue code that makes your application scriptable in Jim, with the following advantages: +- Jim is not the next "little language", but it's a Tcl implementation. + You can reuse your knowledge if you already Tcl skills, or enjoy + the availability of documentation, books, web resources, ... + (for example check my online Tcl book at http://www.invece.org/tclwise) + - Jim is simple, 10k lines of code. If you want to adapt it you can hack the source code to feet the needs of your application. It makes you able to have scripting for default, and avoid external dependences. @@ -79,6 +84,31 @@ scriptable in Jim, with the following advantages: implementation ;). -------------------------------------------------------------------------------- +HOW BIG IS IT? +-------------------------------------------------------------------------------- + +Jim compiled with -Os is 65k currently. Still it lacks core commands +that will make it a little bigger, but not too much... only what's +strictly required will end inside the core, the rest will be implemented +as extensions. + +Note that the actual Jim core is much smaller, if you strip away commands. +If you can do without [expr] (that's big about code size), and some +other command you may probably end with a 40k executable. + +-------------------------------------------------------------------------------- +HOW FAST IS IT? +-------------------------------------------------------------------------------- + +Jim is in most code faster than Tcl7.6p2 (latest 7.x version), +and slower than Tcl 8.4.x. You can expect pretty decent performances +for such a little interpreter. + +If you want a more precise measure, there is 'bench.tcl' inside this +distribution that will run both under Jim and Tcl, so just execute +it with both the interpreters and see what you get :) + +-------------------------------------------------------------------------------- HOW TO COMPILE -------------------------------------------------------------------------------- @@ -28,6 +28,8 @@ EXTENSIONS SPEED OPTIMIZATIONS - Cache call frames instead to free/realloc they at every proc call. + (partially done, now there is to cache the variables has table + contained in the call frames). IMPLEMENTATION ISSUES @@ -36,10 +36,11 @@ set last 42 proc make_gen_random {} { global IM IA IC - set body " + set params [list IM $IM IA $IA IC $IC] + set body [string map $params { global last - expr {(\$max * \[set last \[expr {(\$last * $IA + $IC) % $IM}\]\]) / $IM} - " + expr {($max * [set last [expr {($last * IA + IC) % IM}]]) / IM} + }] proc gen_random {max} $body } @@ -203,6 +204,56 @@ proc dyncode_list {} { } } +### PI DIGITS ################################################################## + +proc pi_digits {} { + set N 300 + set LEN [expr {10*$N/3}] + set result "" + + set a [string repeat " 2" $LEN] + set nines 0 + set predigit 0 + set nines {} + + set i0 [expr {$LEN+1}] + set quot0 [expr {2*$LEN+1}] + for {set j 0} {$j<$N} {incr j} { + set q 0 + set i $i0 + set quot $quot0 + set pos -1 + foreach apos $a { + set x [expr {10*$apos + $q * [incr i -1]}] + lset a [incr pos] [expr {$x % [incr quot -2]}] + set q [expr {$x / $quot}] + } + lset a end [expr {$q % 10}] + set q [expr {$q / 10}] + if {$q < 8} { + append result $predigit $nines + set nines {} + set predigit $q + } elseif {$q == 9} { + append nines 9 + } else { + append result [expr {$predigit+1}][string map {9 0} $nines] + set nines {} + set predigit 0 + } + } + #puts $result$predigit +} + +### EXPAND ##################################################################### + +proc expand {} { + for {set i 0} {$i < 100000} {incr i} { + set a [list a b c d e f] + lappend b {expand}$a + } +} + ### RUN ALL #################################################################### bench {busy loop} {x} @@ -216,3 +267,5 @@ bench {nested loops} {nestedloops} bench {rotate} {rotate 100000} bench {dynamic code} {dyncode} bench {dynamic code (list)} {dyncode_list} +bench {PI digits} {pi_digits} +bench {expand} {expand} @@ -157,7 +157,7 @@ typedef struct Jim_HashTableIterator { } Jim_HashTableIterator; /* This is the initial size of every hash table */ -#define JIM_HT_INITIAL_SIZE 256 +#define JIM_HT_INITIAL_SIZE 32 /* ------------------------------- Macros ------------------------------------*/ #define Jim_FreeEntryVal(ht, entry) \ |