Measuring Script Sizes (LMF and LMFC)
A method of indicating script code and data sizes in REBOL.
Contents
Purpose
To compare scripts, we wanted to have a simple method of judging the true computational (executional) size of a script, a collection of scripts, or data related files.
It turns out that this is trivial to do from any version of REBOL, so the goal was to standardize the method and the terminology.
In a rough way this also serves as a general method of judging program complexity. For example, a 100KB LMFC program is much more complex than a 10KB LMFC. A 1MB LMFC is extremely complex - typically the work of a large team.
Concepts
In REBOL, scripts can be loaded, converted from source code (strings) into blocks of values and words, then molded back into source code (strings again). In doing a mold of a load you can see the true size of the code of a program, less its comments and any special whitespace formatting. Furthermore, if If mold/flat is used, then the beginning whitespace is removed from each line as well. This is not a problem because REBOL automatically inserts indentation if that same flat code is load mold again.
Notations
We will use notations like 10 KB LM and 5 KB LMFC for indicating code sizes (but it works also for data, although that's not related to complexity.)
Here are what the notations mean:
Notation | Description |
---|---|
LM | LOAD then MOLD the code or data. |
LMF | LOAD then MOLD/flat the code or data. |
LMFC | LOAD, MOLD/flat, then COMPRESS the code or data. As small as it can get and still remain the same content. |
A few notes:
- Most of the time, LMFC is the best choice because that is the size of the program when embedded (such as in R2 SDK), stored as apps (in platforms like AltME), or transferred (using smart programs).
- These are just notations used in documentation or forums. It's like writing MB or KB next to a number. It simply clarifies what the number means.
- The reason we call it LM rather than ML is to keep the same alphabetic letter sequence. That is, LMFC not CMFL. So it is in reverse to the actual application of the functions in REBOL.
Examples
Here are a few examples.
Single files
For a single script or data file, the LM size is:
print length? mold load %script.r
The LMF size is:
print length? mold/flat load %script.r
And the LMFC size is:
print length? compress mold/flat load %script.r
Multiple files
Here is a tested example that computes the LM sizes for an application that consists of several files:
REBOL [Title: "Compute LMFC for a set of files."] block: make block! 100 foreach file [ %funcs.r %cgi.r %emit-html.r %scan-doc.r %scan-titles.r %valid-user.r %build-docs.r ][ append block load file ] molded: mold block mold-flat: mold/flat block kb?: func [d] [round/to (length? d) / 1024 .1] print [ "LM:" kb? molded lf "LMF:" kb? mold-flat lf "LMFC:" kb? compress mold-flat lf ]
The results are:
LM: 48.3 LMF: 32.1 LMFC: 11.0