Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #29054
| From | David Kuehling <dvdkhlng@posteo.de> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Measuring execution speed -- profiling in Forth? |
| Date | 2014-03-17 08:00 +0100 |
| Message-ID | <87d2hls41j.fsf@mosquito.pool> (permalink) |
| References | <qdm8i912ie2rkiq7vs310hq3uk0ubud3mj@4ax.com> <53246658$0$25047$e4fe514c@dreader37.news.xs4all.nl> |
>>>>> "Albert" == Albert van der Horst <albert@spenarnc.xs4all.nl> writes: > In article <qdm8i912ie2rkiq7vs310hq3uk0ubud3mj@4ax.com>, > Assad <assad.ebrahim@alum.swarthmore.edu> wrote: [..] >> How to measure the execution speed of an algorithm in Forth? >> >> In other languages, I would use a profiler which would break out the >> execution speed taken by various parts of the code, which is quite >> helpful. >> >> How might one do this in Forth? >> >> If I were to build it myself, I would essentially fetch system time >> (in milliseconds) and then have it accumulate the time spent within a >> word into a variable. >> >> Although I believe someone mentioned that GForth has a profiler...? > On Pentiums practical succes can be had with the real time counter, > allowing for nanosecond resolution. You need a single code word in > assembler. This depends on the Forth. The following code from ciforth > can help: Here is code for Gforth on AMD64 (x86-64)-systems that reads the cycle counter. This should work on any 64-bit x86 linux: abi-code tsc@ ( -- u ) rdtsc .d ax -8 di d) mov .d dx -4 di d) mov -8 di d) ax lea \ compute new sp in result reg ret end-code You can then go on and redefine : and ; to add collect execution count and time information for all forth routines defined in your code. You can see a simple profiler based on this concept is here: http://mosquito.dyndns.tv/opensvn/free/branches/brainless-abi/profiler.fs A more portable version without using the x86 cycle-counter is here: http://sourceforge.net/p/forth-brainless/code/HEAD/tree/trunk/profiler.fs It uses Gforth's CPUTIME word instead (less accurate and more overhead). Of course the overhead added to all definitions is very noticeable and collected timing data will therefore not be representative (unless you are more careful to only enable the profiler on definitions that take about an order of magnitude more execution time than the profiling instrumentation code takes). cheers, David -- GnuPG public key: http://dvdkhlng.users.sourceforge.net/dk2.gpg Fingerprint: B63B 6AF2 4EEB F033 46F7 7F1D 935E 6F08 E457 205F
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Measuring execution speed -- profiling in Forth? Assad <assad.ebrahim@alum.swarthmore.edu> - 2014-03-15 13:48 +0000
Re: Measuring execution speed -- profiling in Forth? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-03-15 14:40 +0000
Re: Measuring execution speed -- profiling in Forth? David Kuehling <dvdkhlng@posteo.de> - 2014-03-17 08:00 +0100
Re: Measuring execution speed -- profiling in Forth? Assad Ebrahim <assad.ebrahim@alum.swarthmore.edu> - 2014-04-01 12:18 +0100
Re: Measuring execution speed -- profiling in Forth? "Elizabeth D. Rather" <erather@forth.com> - 2014-03-15 11:40 -1000
Re: Measuring execution speed -- profiling in Forth? foxaudioresearch@gmail.com - 2014-03-16 15:50 -0700
Re: Measuring execution speed -- profiling in Forth? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-03-16 20:24 -0400
Re: Measuring execution speed -- profiling in Forth? Bernd Paysan <bernd.paysan@gmx.de> - 2014-03-17 01:32 +0100
Re: Measuring execution speed -- profiling in Forth? Coos Haak <chforth@hccnet.nl> - 2014-03-17 01:32 +0100
Re: Measuring execution speed -- profiling in Forth? m.a.m.hendrix@tue.nl - 2014-03-17 01:07 -0700
Re: Measuring execution speed -- profiling in Forth? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-03-17 03:33 -0400
Re: Measuring execution speed -- profiling in Forth? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-03-20 20:43 +0000
Re: Measuring execution speed -- profiling in Forth? "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-03-20 18:54 -0400
Re: Measuring execution speed -- profiling in Forth? Assad <assad.ebrahim@alum.swarthmore.edu> - 2014-03-17 08:23 +0000
csiph-web