Mathpiper Profiler

27 views
Skip to first unread message

Alec Taylor

unread,
Sep 15, 2019, 4:24:52 PM9/15/19
to mathpiper-dev
Ted,

In regards to writing a profiler for mathpiperide, is there a place where mathpiper procedures are called/executed by java code?

-Alec

Ted Kosan

unread,
Sep 15, 2019, 4:38:28 PM9/15/19
to mathpi...@googlegroups.com
Alec,

Excellent question! Yes, all procedures get called from the following class:

mathpiperide/src/library_apps/mathpiper4/src/org/mathpiper/lisp/LispExpressionEvaluator.java

Ted
> --
> You received this message because you are subscribed to the Google Groups "mathpiper-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mathpiper-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mathpiper-dev/33aa3f92-be8d-4657-8c82-d08ebaacb16f%40googlegroups.com.

Alec Taylor

unread,
Sep 15, 2019, 7:17:59 PM9/15/19
to mathpiper-dev
I currently have some gui code inside of LispExpressionEvaluator.java to tell me what procedures are being executed and the duration of the execution (this is just temporary testing for myself), however, it seems like once a procedure is called it no longer runs through evaluator as it isn't showing multiple times in my tests. Is this the case?


On Sunday, September 15, 2019 at 4:38:28 PM UTC-4, tkosan wrote:
Alec,

Excellent question! Yes, all procedures get called from the following class:

mathpiperide/src/library_apps/mathpiper4/src/org/mathpiper/lisp/LispExpressionEvaluator.java

Ted

On Sun, Sep 15, 2019 at 4:24 PM Alec Taylor <alecta...@gmail.com> wrote:
>
> Ted,
>
> In regards to writing a profiler for mathpiperide, is there a place where mathpiper procedures are called/executed by java code?
>
> -Alec
>
> --
> You received this message because you are subscribed to the Google Groups "mathpiper-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mathpi...@googlegroups.com.

Ted Kosan

unread,
Sep 15, 2019, 9:44:36 PM9/15/19
to mathpi...@googlegroups.com
Alec,

This is a good question. LispExpressionEvaluator.java extends
Evaluator.java, and Evaluator.java has a significant amount of tracing
code in it that does get run each time a procedure is evaluated. If
you look at how "TraceOn", "TraceOff", "TraceSome", and "TraceExcept"
use the tracing code that is in Evaluator.java, I think it will give
you some ideas on how profiling might be implemented.

Ted
> To unsubscribe from this group and stop receiving emails from it, send an email to mathpiper-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mathpiper-dev/1e92823b-fe46-4a2c-9a97-a122962dc423%40googlegroups.com.

Alec Taylor

unread,
Oct 6, 2019, 5:23:16 PM10/6/19
to mathpiper-dev
Ted,

I currently have some code that records the time used by every procedure that is called by mathpiper (including startup procedures). This is recorded in both milliseconds and nanoseconds. My next move will be to learn how to implement this by choice rather than default and to place the information in a window within mathpiper rather than a separate swing GUI.

-Alec

Alec Taylor

unread,
Oct 6, 2019, 10:08:13 PM10/6/19
to mathpiper-dev
Ted,

Here is a list of the ten most demanding procedures when starting mathpiperide:

Launch after fresh build:

    And? - 1730ms
    Not? - 1307ms
    Eval - 1141ms
    Sequence - 1119ms
    MacroAssign - 1080ms
    Decide - 791ms
    Assign - 687ms
    Check - 480ms
    Equal? - 360ms
    !? - 168ms

2nd launch:

    And? - 1284ms
    Sequence - 868ms
    Not? - 823ms
    Decide - 677ms
    MacroAssign - 643ms
    Eval - 619ms
    Assign - 405ms
    Check - 331ms
    First - 143ms
    Equal? - 139ms

Mathpiperide launches significantly faster after it has been launched at least once, so I included the procedure times from a second launch as well.

Ted Kosan

unread,
Oct 6, 2019, 11:29:06 PM10/6/19
to mathpi...@googlegroups.com
Alec,

Try doing the following:

1) Copy the following code into
mathpiperide/src/library_apps/mathpiper4/src/org/mathpiper/test/test.mpi
(overwrite the code that is already in this file):

------------------
ProblemSolution()
{
Givens()
{
I~a := 10`mA;
R~a := 820`Ω;

I~b := 65`mA;
R~b := 100`Ω;

I~c := 130`μA;
R~c := 2.7`kΩ;

I~d := 24`mA;
R~d := 1.1`kΩ;

I~e := 800`mA;
R~e := 3.6`Ω;
}

Formulas()
{
f3~1 := Formula(I~I`A == V~V`V / R~R`Ω, Label:"3.1",
Page:"78", Subject:'V~V);

f3~1~a := Formula(f3~1, Label:"a", Substitutions:[I~I -> I~a,
V~V -> V~a, R~R -> R~a]);
f3~1~b := Formula(f3~1, Label:"b", Substitutions:[I~I -> I~b,
V~V -> V~b, R~R -> R~b]);
f3~1~c := Formula(f3~1, Label:"c", Substitutions:[I~I -> I~c,
V~V -> V~c, R~R -> R~c]);
f3~1~d := Formula(f3~1, Label:"d", Substitutions:[I~I -> I~d,
V~V -> V~d, R~R -> R~d]);
f3~1~e := Formula(f3~1, Label:"e", Substitutions:[I~I -> I~e,
V~V -> V~e, R~R -> R~e]);
}

V~a := EvaluateFormula(f3~1~a, V);
V~b := EvaluateFormula(f3~1~b, V);
V~c := EvaluateFormula(f3~1~c, mV);
V~d := EvaluateFormula(f3~1~d, V);
V~e := EvaluateFormula(f3~1~e, V);
}
-----------------

2) Open mathpiperide/src/library_apps/mathpiper4/src/org/mathpiper/test/InterpreterTest.java
in NetBeans, and run it by right clicking on it. This will run the
code in the .mpi file.

3) Add code to the .mpi file or to this Java file that will profile
the code that is in the .mpi file. The procedures I am hoping to
profile are the ones that are defined in
mathpiperide/src/library_apps/mathpiper4/src/org/mathpiper/scripts4/units/mpunits.mpws
and in mathpiperide/src/library_apps/mathpiper4/src/org/mathpiper/scripts4/units/mpunits_private.mpws.

4) Profile the code that is in the .mpi file, and let me know if any
of the units procedures are especially slow.

Ted
> To unsubscribe from this group and stop receiving emails from it, send an email to mathpiper-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mathpiper-dev/03c90961-2bf0-4266-81ed-31a40ff1f499%40googlegroups.com.

Alec Taylor

unread,
Oct 8, 2019, 10:24:04 AM10/8/19
to mathpiper-dev
Ted,

Here are the ms values for the Units procedures used in the code you provided:

CharacterSymbol? - 2614ms
FundamentalUnitsOf - 1105ms
PureUnitsToStandardUnits - 717ms
` - 25ms
RecognizedUnit? - 7ms
DimensionsOf - 6ms
# - 3ms
UnitsToFundamentalForm - 2ms
UnitOf - 1ms
SIUnit? - 1ms
ConvertUnits - 1ms
UnitsReduce - 1ms
SimplifyUnits - 1ms
ValueOf - 0ms
DimensionsAsListOf - 0ms
UnitsInit - 0ms

CharacterSymbol?, FundamentalUnitsOf, PureUnitsToStandardUnits by far take the most time to execute.

-Alec
> To view this discussion on the web visit https://groups.google.com/d/msgid/mathpiper-dev/03c90961-2bf0-4266-81ed-31a40ff1f499%40googlegroups.com.

Alec Taylor

unread,
Oct 8, 2019, 10:28:09 AM10/8/19
to mathpiper-dev
Its probably important that I mention my code measures each procedure time and sums them up, so these procedure times are calculated as a total rather than the time measured from a single execution.

Ted Kosan

unread,
Oct 8, 2019, 11:31:38 AM10/8/19
to mathpi...@googlegroups.com
Alec,

Excellent work!

The next step is to determine why "CharacterSymbol?" is at the top of
the list. Here is this procedure's definition:

CharacterSymbol?(expression) :=
{
Atom?(expression) &? RecognizedUnit?(expression);
}

What do you think is implied by the fact that "CharacterSymbol?" takes
2614ms of time while "RecognizedUnit?" (which "CharacterSymbol?"
calls) only takes 7ms of time?

Ted
> To unsubscribe from this group and stop receiving emails from it, send an email to mathpiper-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mathpiper-dev/76b044e9-c5ae-4b29-92f2-6bb676d4e94c%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages