scsh-users
[Top] [All Lists]

timing threads

To: scsh-news@zurich.ai.mit.edu
Subject: timing threads
From: sgelkins@bellsouth.net (Steve Elkins)
Date: 25 Oct 2002 07:16:02 -0700
Organization: http://groups.google.com/
Scsh continues delighting me.

See http://www.mozart-oz.org/documentation/apptut/node9.html#death.in.oz 
for the inspiration of this little exercise.

========================================================================

#!/usr/local/bin/scsh \
-o threads -e go -s
!#

;; ~/scsh/thread-fun.scm

(define (go prog+args)
  (let ((args (cdr prog+args)))
    (let ((threads (string->number (car args)))
          (times (string->number (cadr args))))
      (let loop ((i 0))
        (spawn (lambda ()
                 (let loop ((i 0))
                   (relinquish-timeslice)
                   (if (< i times)
                       (loop (+ i 1))))))
        (if (< i threads)
            (loop (+ i 1)))))))

========================================================================

sge:/home/sge/scsh:7$ time ./thread-fun.scm 100 10
    0.08s real     0.07s user     0.01s system
sge:/home/sge/scsh:8$ time ./thread-fun.scm 1000 10
    1.26s real     1.23s user     0.02s system
sge:/home/sge/scsh:9$ time ./thread-fun.scm 10000 10
  115.55s real   114.21s user     0.09s system
sge:/home/sge/scsh:10$ time ./thread-fun.scm 1000 100
    1.27s real     1.24s user     0.02s system
sge:/home/sge/scsh:11$ time ./thread-fun.scm 1000 1000
    1.27s real     1.23s user     0.03s system
sge:/home/sge/scsh:12$ time ./thread-fun.scm 5000 10
   29.71s real    29.59s user     0.04s system
sge:/home/sge/scsh:13$ time ./thread-fun.scm 2000 10
    5.10s real     4.96s user     0.08s system
sge:/home/sge/scsh:14$ time ./thread-fun.scm 1000 10000
    1.28s real     1.25s user     0.01s system
sge:/home/sge/scsh:15$ time ./thread-fun.scm 1000 100000
    1.28s real     1.25s user     0.01s system
sge:/home/sge/scsh:16$ time ./thread-fun.scm 1000 1000000
    1.28s real     1.21s user     0.04s system
sge:/home/sge/scsh:17$ time ./thread-fun.scm 1000 10000000
    1.28s real     1.22s user     0.05s system

========================================================================

#!/usr/local/bin/scsh \
-e go -s
!#

;; ~/scsh/run-thread-fun.scm

(define (go _)
  (format #t "Threads\tTimes\tReal\tUser\tSystem\n")
  (let loop ((threads 10))
    (let loop ((times 10))
      (let ((strings ((field-splitter)
                      (run/string (time /home/sge/scsh/thread-fun.scm
                                        ,threads ,times)
                                  (= 2 1)))))
        (format #t "~s\t~s\t~a\t~a\t~a\n"
                threads times (car strings) (caddr strings)
                (list-ref strings 4)))
      (if (< times 10000)
          (loop (* 10 times))))
    (if (< threads 10000)
        (loop (* 10 threads)))))

========================================================================

sge:/home/sge/scsh:32$ ./run-thread-fun.scm
Threads Times   Real    User    System
10      10      0.05    0.03    0.01
10      100     0.05    0.05    0.00
10      1000    0.05    0.03    0.02
10      10000   0.05    0.03    0.02
100     10      0.07    0.05    0.02
100     100     0.07    0.04    0.02
100     1000    0.07    0.04    0.03
100     10000   0.07    0.05    0.01
1000    10      1.28    1.25    0.00
1000    100     1.28    1.21    0.03
1000    1000    1.28    1.26    0.00
1000    10000   1.27    1.22    0.03
10000   10      134.83  133.50  0.02
10000   100     115.83  114.68  0.04
10000   1000    128.95  127.64  0.03
10000   10000   128.91  127.74  0.09
sge:/home/sge/scsh:33$ ./run-thread-fun.scm
Threads Times   Real    User    System
10      10      0.06    0.04    0.00
10      100     0.05    0.03    0.01
10      1000    0.05    0.05    0.00
10      10000   0.05    0.03    0.02
100     10      0.07    0.04    0.02
100     100     0.07    0.04    0.02
100     1000    0.07    0.06    0.00
100     10000   0.07    0.06    0.00
1000    10      1.27    1.24    0.01
1000    100     1.28    1.21    0.04
1000    1000    1.27    1.25    0.00
1000    10000   1.26    1.21    0.04
10000   10      129.47  128.05  0.05
10000   100     115.36  114.42  0.07
10000   1000    136.27  134.95  0.06
10000   10000   115.97  114.72  0.05

========================================================================

So...scsh switches contexts nearly instantaneously and increasing the
number of threads costs more than the linear amount.  If anyone else
runs the script(s), I would be interested to know if the results are
similar.

-- 
The student in question is performing minimally for his peer group and
is an emerging underachiever.

<Prev in Thread] Current Thread [Next in Thread>