diff --git a/bin/ikarus b/bin/ikarus index 4191d2d..b9066db 100755 Binary files a/bin/ikarus and b/bin/ikarus differ diff --git a/bin/ikarus-runtime.c b/bin/ikarus-runtime.c index 1938d61..365240e 100644 --- a/bin/ikarus-runtime.c +++ b/bin/ikarus-runtime.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include @@ -858,3 +860,23 @@ ikrt_register_guardian(ikp tc, ikp obj, ikpcb* pcb){ g->count++; return 0; } + + +ikp +ikrt_stats_now(ikp t, ikpcb* pcb){ + struct rusage r; + struct timeval s; + + gettimeofday(&s, 0); + getrusage(RUSAGE_SELF, &r); + ref(t, off_record_data) = fix(r.ru_utime.tv_sec); + ref(t, off_record_data + wordsize) = fix(r.ru_utime.tv_usec); + ref(t, off_record_data + 2 * wordsize) = fix(r.ru_stime.tv_sec); + ref(t, off_record_data + 3 * wordsize) = fix(r.ru_stime.tv_usec); + ref(t, off_record_data + 4 * wordsize) = fix(s.tv_sec); + ref(t, off_record_data + 5 * wordsize) = fix(s.tv_usec); + return void_object; +} + + + diff --git a/lab/sudoku.txt b/lab/sudoku.txt index fc2007c..03be64f 100644 --- a/lab/sudoku.txt +++ b/lab/sudoku.txt @@ -498,3 +498,1143 @@ "009040301" "000702000" "000008006") +("grid" + "400000805" + "030000000" + "000700000" + "020000060" + "000080400" + "000010000" + "000603070" + "500200000" + "104000000") + + +("grid" + "520006000" + "000000701" + "300000000" + "000400800" + "600000050" + "000000000" + "041800000" + "000030020" + "008700000") + + +("grid" + "600000803" + "040700000" + "000000000" + "000504070" + "300200000" + "106000000" + "020000050" + "000080600" + "000010000") + + +("grid" + "480300000" + "000000071" + "020000000" + "705000060" + "000200800" + "000000000" + "001076000" + "300000400" + "000050000") + + +("grid" + "000014000" + "030000200" + "070000000" + "000900030" + "601000000" + "000000080" + "200000104" + "000050600" + "000708000") + + +("grid" + "000000520" + "080400000" + "030009000" + "501000600" + "200700000" + "000300000" + "600010000" + "000000704" + "000000030") + + +("grid" + "602050000" + "000003040" + "000000000" + "430008000" + "010000200" + "000000700" + "500270000" + "000000081" + "000600000") + + +("grid" + "052400000" + "000070100" + "000000000" + "000802000" + "300000600" + "090500000" + "106030000" + "000000089" + "700000000") + + +("grid" + "602050000" + "000004030" + "000000000" + "430008000" + "010000200" + "000000700" + "500270000" + "000000081" + "000600000") + + +("grid" + "092300000" + "000080100" + "000000000" + "107040000" + "000000065" + "800000000" + "060502000" + "400000700" + "000900000") + + +("grid" + "600302000" + "050000010" + "000000000" + "702600000" + "000000054" + "300000000" + "080150000" + "000040200" + "000000700") + + +("grid" + "060501090" + "100090053" + "900007000" + "040800070" + "000000508" + "081705030" + "000050200" + "000000000" + "076008000") + + +("grid" + "005000987" + "040050001" + "007000000" + "200048000" + "090100000" + "600200000" + "300600200" + "000009070" + "000000500") + + +("grid" + "306070000" + "000000051" + "800000000" + "010405000" + "700000600" + "000200000" + "020000040" + "000080300" + "000500000") + + +("grid" + "100000308" + "070400000" + "000000000" + "203010000" + "000000095" + "800000000" + "050600070" + "000080200" + "040000000") + + +("grid" + "600302000" + "040000010" + "000000000" + "702600000" + "000000054" + "300000000" + "080150000" + "000040200" + "000000700") + + +("grid" + "000030090" + "000200001" + "050900000" + "000000000" + "102080406" + "080500020" + "075000000" + "401006003" + "000004060") + + +("grid" + "450000030" + "000801000" + "090000000" + "000050090" + "200700000" + "800000000" + "010040000" + "000000702" + "000600800") + + +("grid" + "023700006" + "800060590" + "900000700" + "000040970" + "307096002" + "000000000" + "500470000" + "000002000" + "080000000") + + +("grid" + "008400030" + "000300000" + "900001574" + "790008000" + "000007005" + "140000020" + "009060002" + "050000400" + "000090056") + + +("grid" + "098010000" + "200000060" + "000000000" + "000302050" + "084000000" + "000600000" + "000040809" + "300500000" + "000000100") + + +("grid" + "002470058" + "000000000" + "000001040" + "000020009" + "528090400" + "009000100" + "000000030" + "300007500" + "685002000") + + +("grid" + "400000805" + "030000000" + "000700000" + "020000060" + "000050400" + "000010000" + "000603070" + "500200000" + "109000000") + + +("grid" + "020300000" + "063000005" + "800000001" + "500009030" + "000700000" + "000100008" + "087900260" + "000006070" + "006007004") + + +("grid" + "100000709" + "040007200" + "800000000" + "070010060" + "300000005" + "060040020" + "000000008" + "005300070" + "702000046") + + +("grid" + "400000300" + "000802000" + "000700000" + "000100087" + "340000000" + "600000000" + "500060000" + "000010400" + "082000000") + + +("grid" + "000000071" + "020800000" + "000403000" + "700060050" + "000200300" + "900000000" + "600070000" + "080000400" + "000050000") + + +("grid" + "600302000" + "040000080" + "000000000" + "702600000" + "000000054" + "300000000" + "080150000" + "000080200" + "000000700") + + +("grid" + "047080001" + "000000000" + "000600700" + "600003570" + "000005000" + "010060000" + "280040000" + "090100040" + "000020690") + + +("grid" + "000000801" + "700200000" + "000506000" + "000700050" + "010000300" + "080000000" + "500000020" + "040080000" + "600030000") + + +("grid" + "380600000" + "009000000" + "020030510" + "000005000" + "030010060" + "000400000" + "017050080" + "000000900" + "000007032") + + +("grid" + "000500000" + "000000506" + "970000020" + "004802000" + "250100030" + "080030000" + "000004070" + "013050090" + "020003100") + + +("grid" + "020000000" + "305062009" + "068000300" + "050000000" + "000640802" + "004700900" + "003000001" + "000006000" + "170430000") + + +("grid" + "080040000" + "300000010" + "000000020" + "005000406" + "900100800" + "200000000" + "000309000" + "060000500" + "000200000") + + +("grid" + "008090100" + "060500020" + "000006000" + "030107050" + "000000009" + "004000300" + "050000200" + "070003080" + "200700004") + + +("grid" + "400000508" + "030000000" + "000700000" + "020000060" + "000050800" + "000010000" + "000603070" + "500200000" + "108000000") + + +("grid" + "100000308" + "060400000" + "000000000" + "203010000" + "000000095" + "800000000" + "050600070" + "000080200" + "040000000") + + +("grid" + "100006080" + "064000000" + "000040007" + "000090600" + "070400500" + "500070100" + "050000320" + "300008000" + "400000000") + + +("grid" + "249060003" + "030000200" + "800000005" + "000006000" + "000200000" + "010040820" + "090500700" + "004000001" + "070003000") + + +("grid" + "000800009" + "087300040" + "600700000" + "008500970" + "000000000" + "043007500" + "000003000" + "030001450" + "400002001") + + +("grid" + "000501000" + "090000800" + "060000000" + "401000000" + "000070090" + "000000030" + "800000105" + "000200400" + "000360000") + + +("grid" + "000000801" + "600200000" + "000705000" + "000600020" + "010000300" + "080000000" + "200000070" + "030080000" + "500040000") + + +("grid" + "047600050" + "803000002" + "000009000" + "000805006" + "000100000" + "602400000" + "078000510" + "006000040" + "090004007") + + +("grid" + "000007095" + "000001000" + "860020000" + "020073008" + "500000060" + "003004900" + "305000417" + "240000000" + "000000000") + + +("grid" + "040500000" + "800090030" + "076020000" + "014600000" + "000009007" + "000003600" + "001004050" + "060000003" + "007100200") + + +("grid" + "083400000" + "000070050" + "000000000" + "040108000" + "000000027" + "000300000" + "206050000" + "500000800" + "000000100") + + +("grid" + "009000003" + "000009000" + "700000506" + "006500400" + "000300000" + "028000000" + "300750600" + "600000000" + "000120308") + + +("grid" + "026039000" + "000600001" + "900000700" + "000004009" + "050000200" + "008500000" + "300200900" + "400007620" + "000000004") + + +("grid" + "203080000" + "800700000" + "000000100" + "060507000" + "400000030" + "000100000" + "000000082" + "050000600" + "010000000") + + +("grid" + "600302000" + "010000050" + "000000000" + "702600000" + "000000084" + "300000000" + "080150000" + "000080200" + "000000700") + + +("grid" + "100000900" + "064001070" + "070040000" + "000300000" + "308900500" + "007000020" + "000060709" + "000004010" + "000129030") + + +("grid" + "000000000" + "900000084" + "062300050" + "000600045" + "300010006" + "000900070" + "000100000" + "405002000" + "030800009") + + +("grid" + "020000593" + "800500460" + "940060008" + "002030000" + "060080730" + "700200000" + "000040380" + "070000600" + "000000005") + + +("grid" + "904005000" + "250600100" + "310000008" + "070009000" + "400260000" + "001470000" + "700000002" + "000300806" + "040000090") + + +("grid" + "000520000" + "090003004" + "000000700" + "010000040" + "080045300" + "600010008" + "702000000" + "008000032" + "040080010") + + +("grid" + "530020900" + "024030050" + "009000000" + "000010827" + "000700000" + "000098100" + "000000000" + "006400009" + "102050430") + + +("grid" + "100007860" + "007008010" + "800200009" + "000000002" + "400010000" + "009005000" + "608000000" + "000050900" + "000009304") + + +("grid" + "000050001" + "100000070" + "060000080" + "000004000" + "009010300" + "000596020" + "080062007" + "007000000" + "305070200") + + +("grid" + "047020000" + "800001000" + "030000902" + "000005000" + "600810050" + "000040000" + "070000304" + "000900010" + "400270800") + + +("grid" + "000000940" + "000090005" + "300005070" + "080400100" + "463000000" + "000007080" + "800700000" + "700000028" + "050260000") + + +("grid" + "020000006" + "000041000" + "007800001" + "000000700" + "003700000" + "600412000" + "010074005" + "008050070" + "000003900") + + +("grid" + "100000308" + "060400000" + "000000000" + "203010000" + "000000075" + "800000000" + "070500060" + "000080200" + "040000000") + + +("grid" + "200001090" + "010030700" + "900800020" + "000000850" + "060400000" + "000070003" + "020300060" + "000500000" + "109000205") + + +("grid" + "007008000" + "006020300" + "030000009" + "010050060" + "000010000" + "070900002" + "000000004" + "083004000" + "260000510") + + +("grid" + "000360000" + "850000000" + "904008000" + "000006800" + "000000017" + "009004500" + "010500060" + "400009002" + "000003000") + + +("grid" + "340600000" + "007000000" + "020080570" + "000005000" + "070010020" + "000400000" + "036020010" + "000000900" + "000007082") + + +("grid" + "000000401" + "800200000" + "000607000" + "000800060" + "040000300" + "010000000" + "600000020" + "050010000" + "700030000") + + +("grid" + "040050067" + "000100040" + "000200000" + "100800300" + "000000200" + "060000000" + "000040050" + "300000800" + "200000000") + + +("grid" + "000000040" + "002004001" + "070050090" + "003007000" + "040060000" + "600100800" + "020000100" + "850900060" + "000080003") + + +("grid" + "800700004" + "050000600" + "000000000" + "030970008" + "000043005" + "000020900" + "006000000" + "200060007" + "071008302") + + +("grid" + "080004050" + "000700300" + "000000000" + "010085000" + "600000200" + "000040000" + "302600000" + "000000041" + "700000000") + + +("grid" + "000070080" + "006000500" + "020003061" + "010007002" + "008005340" + "200900000" + "002000000" + "580006030" + "400010000") + + +("grid" + "000000801" + "600200000" + "000705000" + "000600020" + "010000300" + "080000000" + "200000070" + "040080000" + "500030000") + + +("grid" + "020000000" + "000600003" + "074080000" + "000003002" + "080040010" + "600500000" + "000010780" + "500009000" + "000000040") + + +("grid" + "052006800" + "000007020" + "000000600" + "004800900" + "200410000" + "001000008" + "006100380" + "000090006" + "300600109") + + +("grid" + "000010780" + "500009000" + "000000040" + "020000000" + "000600003" + "074080000" + "000003002" + "080040010" + "600500000") + + +("grid" + "100000003" + "060300700" + "070005001" + "210700090" + "007000000" + "008010020" + "000806400" + "009020060" + "000400000") + + +("grid" + "400070100" + "001904605" + "000001000" + "000700002" + "002030000" + "847006000" + "014000806" + "020000300" + "600090000") + + +("grid" + "000000801" + "700200000" + "000506000" + "000700050" + "010000300" + "080000000" + "500000020" + "030080000" + "600040000") + + +("grid" + "963000000" + "100008000" + "000205000" + "040800000" + "010000700" + "000030025" + "700000030" + "009020407" + "000000900") + + +("grid" + "150300000" + "070040200" + "004072000" + "008000000" + "000900108" + "010080790" + "000003800" + "000000000" + "600007423") + + +("grid" + "000000000" + "057240009" + "800009470" + "009003000" + "500900120" + "003010900" + "060000250" + "000560000" + "070000006") + + +("grid" + "000075000" + "010020000" + "040003000" + "500000302" + "000800010" + "000000600" + "000100480" + "200000000" + "700000000") + + +("grid" + "600000703" + "040800000" + "000000000" + "000504080" + "700200000" + "103000000" + "020000050" + "000070900" + "000010000") + + +("grid" + "000060004" + "006030000" + "100400507" + "700000805" + "000800000" + "608000090" + "002090000" + "400003200" + "009700100") + + +("grid" + "032000005" + "800300000" + "904280001" + "000400039" + "000600050" + "000010000" + "020006708" + "000004000" + "095000060") + + +("grid" + "000503000" + "000060700" + "508000016" + "360020000" + "000401000" + "000030005" + "670000208" + "004070000" + "000200500") + + +("grid" + "050307040" + "100000000" + "030000000" + "508030610" + "000800509" + "060010000" + "000040006" + "000692700" + "002000900") + + +("grid" + "005008001" + "800000090" + "000000780" + "000400000" + "640000900" + "000053002" + "060000000" + "001380050" + "000907140") + + +("grid" + "000000000" + "072060100" + "005100082" + "080001300" + "400000000" + "037090010" + "000023800" + "504009000" + "000000790") + + +("grid" + "000658000" + "004000000" + "120000000" + "000009607" + "000300500" + "002080003" + "001900800" + "306000004" + "000047300") + + +("grid" + "020300000" + "006008090" + "830500000" + "000200080" + "709005000" + "000006004" + "000000010" + "001000402" + "200700809") + + +("grid" + "050090000" + "100000600" + "000308000" + "008040009" + "514000000" + "030000200" + "000000004" + "080006007" + "700150060") + + +("grid" + "000002000" + "000070001" + "700300090" + "800700000" + "020890600" + "013006000" + "090050824" + "000008910" + "000000000") + + +("grid" + "300080000" + "000700005" + "100000000" + "000000360" + "002004000" + "070000000" + "000060130" + "045200000" + "000000800") + + diff --git a/src/ikarus.boot b/src/ikarus.boot index cd2570d..8bfb891 100644 Binary files a/src/ikarus.boot and b/src/ikarus.boot differ diff --git a/src/libtimers.ss b/src/libtimers.ss new file mode 100644 index 0000000..44c46a3 --- /dev/null +++ b/src/libtimers.ss @@ -0,0 +1,58 @@ + +(let () + (define-record stats + (user-secs user-usecs sys-secs sys-usecs real-secs real-usecs)) + + (define (mk-stats) + (make-stats #f #f #f #f #f #f)) + + (define (set-stats! t) + (foreign-call "ikrt_stats_now" t)) + + (define (print-stats message t1 t0) + (define (print-time msg secs usecs) + (if (fx< usecs 0) + (print-time msg (fx- secs 1) (fx+ usecs 1000000)) + (printf " ~a.~a~a~as ~a time\n" + secs + (fxremainder (fxquotient usecs 100000) 10) + (fxremainder (fxquotient usecs 10000) 10) + (fxremainder (fxquotient usecs 1000) 10) + msg))) + (if message + (printf "running stats for ~a:\n" message) + (printf "running stats:\n")) + (print-time "user" + (fx- (stats-user-secs t1) (stats-user-secs t0)) + (fx- (stats-user-usecs t1) (stats-user-usecs t0))) + (print-time "system" + (fx- (stats-sys-secs t1) (stats-sys-secs t0)) + (fx- (stats-sys-usecs t1) (stats-sys-usecs t0))) + (print-time "real" + (fx- (stats-real-secs t1) (stats-real-secs t0)) + (fx- (stats-real-usecs t1) (stats-real-usecs t0)))) + + (define time-it + (case-lambda + [(proc) + (time-it proc #f)] + [(proc message) + (unless (procedure? proc) + (error 'time-it "~s is not a procedure" proc)) + (let* ([t1 (mk-stats)] + [t0 (mk-stats)]) + (set-stats! t0) + (call-with-values proc + (case-lambda + [(v) + (set-stats! t1) + (print-stats message t1 t0) + v] + [v* + (set-stats! t1) + (print-stats message t1 t0) + (apply values v*)])))])) + + (primitive-set! 'time-it time-it) + +) diff --git a/src/makefile.ss b/src/makefile.ss index ad77e78..ebfefea 100755 --- a/src/makefile.ss +++ b/src/makefile.ss @@ -25,7 +25,8 @@ syntax-case syntax-rules module $module import $import import-only syntax quasisyntax unsyntax unsyntax-splicing datum let let* let-values cond case define-record or and when unless do - include parameterize trace untrace trace-lambda trace-define)) + include parameterize trace untrace trace-lambda trace-define + time)) @@ -84,6 +85,7 @@ negative? zero? number->string logand = < > <= >= make-guardian weak-cons collect interrupt-handler + time-it )) (define system-primitives @@ -230,6 +232,7 @@ ["libcafe.ss" "libcafe.fasl"] ["libtrace.ss" "libtrace.fasl"] ["libposix.ss" "libposix.fasl"] + ["libtimers.ss" "libtimers.fasl"] ["libtoplevel.ss" "libtoplevel.fasl"] )) diff --git a/src/psyntax-7.1.ss b/src/psyntax-7.1.ss index 8a45f1d..0f2fc81 100644 --- a/src/psyntax-7.1.ss +++ b/src/psyntax-7.1.ss @@ -4669,3 +4669,9 @@ #'(define id (make-traced-procedure 'id value))]))) +(define-syntax time + (lambda (x) + (syntax-case x () + [(_ expr) + #'(time-it (lambda () expr) 'expr)]))) +