cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Prime interpreter speed test (surprising result)

DS_10314450
6-Contributor

Prime interpreter speed test (surprising result)

Good morning, 

 

I am running some deeper simulations in P8 and noted that the CPU grind was pretty fast. I was surprised at this and ran a simple side-by-side with compiled C on a simple summation test.  I found that the slowdown ratio was only about x25.  In similar tests, I have found Python to be about x200 to x500.  I'd be interested to know how P8 has achieved this.  Perhaps the developers could comment.MCAD Posting CPU Grind.png 

 

Here is the C++ project 

 

 

/* time example */
#include <stdio.h>      /* printf */
#include <time.h>       /* time_t, struct tm, difftime, time, mktime */
#include <iostream>

double F_SUM()
{
   double SUM = 0;
   for (long i = 0; i < 1000000000; i++)
   {
      SUM += i;

   }
   return SUM;
}

int main()
{
   //clock_t clock(void) returns the number of clock ticks elapsed since the program was launched.To get the number of seconds used by the CPU you will need to divide by CLOCKS_PER_SEC
   
   clock_t t_STR;
   clock_t t_END;

   double dt_CPU;

   // Recording the starting clock tick
   t_STR = clock();

   double SUM = F_SUM();

   // Recording the end clock tick.
   t_END = clock();

   // Calculating total time taken by the program.
   dt_CPU = double(t_END - t_STR) / double(CLOCKS_PER_SEC);

   std::cout << "Time taken by program is : " << dt_CPU << ", SUM = " << SUM;

   return 0;
}

 

 

I went back and did a comparable Python test which shows Python is about x4 slower than P8:

 

Here is the Python code:

import time

t_STR = time.time()
SUM = 0
N = 1000000000
for i in range(N):
    SUM += i

dt_CPU = time.time()- t_STR

print(SUM, dt_CPU)

 

Results:

MCAD Posting CPU Grind.png

Regards 

1 REPLY 1


@DS_10314450 wrote:

Good morning, 

 

I am running some deeper simulations in P8 and noted that the CPU grind was pretty fast. I was surprised at this and ran a simple side-by-side with compiled C on a simple summation test.  I found that the slowdown ratio was only about x25.  In similar tests, I have found Python to be about x200 to x500.  I'd be interested to know how P8 has achieved this.  Perhaps the developers could comment.
....

 

Here is the C++ project 

 

...

I went back and did a comparable Python test which shows Python is about x4 slower than P8:

I suspect that there may be an assumption in your thread title.

 

I'm not a developer, but I suspect that Prime 8 (and earlier versions plus Mathcad 12 onwards) don't use a direct Mathcad interpreter.  

 

Instead, I think that they compile the worksheet to an intermediate, and partially optimised, code that itself is either interpreted or compiled.    I believe that Mathcad 12..15 compiled down to the Mathcad Programming Language (MPL), which looked awfully like Haskell.  

 

I vaguely recall there being some hints that the MPL definition would be firmed up and users given the ability to write MPL code that Mathcad would pick up at load time or access via a component or be able to be used in "programming" constructs.   Nothing came of this, however.

 

Stuart

Top Tags