Load Mold Sizes

From DocBase

Jump to: navigation, search

This is a method of measuring script and data sizes in REBOL.

Contents

Purpose

This provides a simple method of judging the true computational (executional) size of a script, collection of scripts, or data related files.

It is trivial to do this from any version of REBOL; therefore, making it useful as a common method of measurement.

This also serves as a general method of judging program complexity, in rough orders of magnitude.

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.

Theory

REBOL scripts can be LOADED, converted from source code (strings) into blocks of values and words.

These blocks can be MOLDED back into source code (strings again).

In using MOLD of a LOAD, we can see the true size of the code of a program, less its comments and any special whitespace formatting.

If MOLD/flat is used, then all 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 MOLDed 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.)

Note that 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.

Here are what the notations mean:

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.

For most cases, the 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).

Note, 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

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
Personal tools