FH
Father Horton
Sun, Feb 9, 2025 8:37 PM
That's assuming OpenSCAD doesn't memoize module calls, which I strongly
doubt it does.
On Sun, Feb 9, 2025 at 2:35 PM Father Horton fatherhorton@gmail.com wrote:
You might have to resort to invoking it 10^6 times (or more) and using the
overall execution time to get an estimate.
On Sun, Feb 9, 2025 at 2:34 PM John David via Discuss <
discuss@lists.openscad.org> wrote:
I was thinking along the lines of:
start = time();
mymodule();
echo(time() - start);
If time is given in ms, then this makes sense. This is how the RenderStatistic.h source calculates the elapsetime.
If we had a time() function, and possibly a time_diff function, then I can calculate the elapse time of different solutions.
EBo --
On Sun, Feb 9, 2025 at 2:56 PM Torsten Paul via Discuss <
discuss@lists.openscad.org> wrote:
On 09.02.25 19:25, Adrian Mariano via Discuss wrote:
Wouldn't it be possible to have an elapsed time measurement for
functions? The majority of time testing I do is for functions, not
geometry production.
There we go, good question as that refers to the first evaluation
step of the processing. I'm not sure what the original post
was asking, but I was assuming that was more about the 2nd part of
processing which is either GUI display or Mesh Render depending
on Preview/Render mode.
Functions are part of the AST, so I guess we would need to do
the annotation for both AST and geometry tree.
What I'm saying is it's not solved by a simple "measure()"
regardless of function evaluation or mesh render. That will
only help in some special cases.
Main point is that an OpenSCAD "program" is multiple steps
that are processing tree structures. It's not a single linear
code flow.
ciao,
Torsten.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
That's assuming OpenSCAD doesn't memoize module calls, which I strongly
doubt it does.
On Sun, Feb 9, 2025 at 2:35 PM Father Horton <fatherhorton@gmail.com> wrote:
> You might have to resort to invoking it 10^6 times (or more) and using the
> overall execution time to get an estimate.
>
> On Sun, Feb 9, 2025 at 2:34 PM John David via Discuss <
> discuss@lists.openscad.org> wrote:
>
>> I was thinking along the lines of:
>>
>> start = time();
>> mymodule();
>> echo(time() - start);
>>
>> If time is given in ms, then this makes sense. This is how the RenderStatistic.h source calculates the elapsetime.
>>
>> If we had a time() function, and possibly a time_diff function, then I can calculate the elapse time of different solutions.
>>
>> EBo --
>>
>>
>> On Sun, Feb 9, 2025 at 2:56 PM Torsten Paul via Discuss <
>> discuss@lists.openscad.org> wrote:
>>
>>> On 09.02.25 19:25, Adrian Mariano via Discuss wrote:
>>> > Wouldn't it be possible to have an elapsed time measurement for
>>> > functions? The majority of time testing I do is for functions, not
>>> > geometry production.
>>>
>>> There we go, good question as that refers to the first evaluation
>>> step of the processing. I'm not sure what the original post
>>> was asking, but I was assuming that was more about the 2nd part of
>>> processing which is either GUI display or Mesh Render depending
>>> on Preview/Render mode.
>>>
>>> Functions are part of the AST, so I guess we would need to do
>>> the annotation for both AST and geometry tree.
>>>
>>> What I'm saying is it's not solved by a simple "measure()"
>>> regardless of function evaluation or mesh render. That will
>>> only help in some special cases.
>>>
>>> Main point is that an OpenSCAD "program" is multiple steps
>>> that are processing tree structures. It's not a single linear
>>> code flow.
>>>
>>> ciao,
>>> Torsten.
>>> _______________________________________________
>>> OpenSCAD mailing list
>>> To unsubscribe send an email to discuss-leave@lists.openscad.org
>>>
>> _______________________________________________
>> OpenSCAD mailing list
>> To unsubscribe send an email to discuss-leave@lists.openscad.org
>>
>
SL
Steve Lelievre
Sun, Feb 9, 2025 8:44 PM
We’re told in the user guide not to assume OpenSCAD is sequential, so is
that approach even technically possible?
On Sun, 9 Feb 2025 at 12:34, John David via Discuss <
discuss@lists.openscad.org> wrote:
I was thinking along the lines of:
start = time();
mymodule();
echo(time() - start);
We’re told in the user guide not to assume OpenSCAD is sequential, so is
that approach even technically possible?
On Sun, 9 Feb 2025 at 12:34, John David via Discuss <
discuss@lists.openscad.org> wrote:
> I was thinking along the lines of:
>
> start = time();
> mymodule();
> echo(time() - start);
>
>
R
Rudolf
Sun, Feb 9, 2025 10:21 PM
If you just intend to do some runtime-tests on previews and renders (F5
and F6), you can exploit the "Total rendering time" information provided
in the console window. However don't forget to clear the cache if
modules are involved.
Am 09.02.2025 um 19:10 schrieb John David via Discuss:
I want to do a bunch of timing tests, but as far as I can tell, there
are no functions to pull the wall clock time and derive an elapse time.
Does anyone know of how to do this, or do we need to hack in a new
built-in function?
EBo --
OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org
If you just intend to do some runtime-tests on previews and renders (F5
and F6), you can exploit the "Total rendering time" information provided
in the console window. However don't forget to clear the cache if
modules are involved.
Am 09.02.2025 um 19:10 schrieb John David via Discuss:
> I want to do a bunch of timing tests, but as far as I can tell, there
> are no functions to pull the wall clock time and derive an elapse time.
>
> Does anyone know of how to do this, or do we need to hack in a new
> built-in function?
>
> EBo --
>
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email todiscuss-leave@lists.openscad.org
JD
John David
Mon, Feb 10, 2025 1:28 AM
I was asked to do some simple until tests for two alternatives of the
nurbs_length() function. So far I have written some simple tests, and
copy/pasted the results run one at a time. It would be nice to set up a
dozen edge cases and run them all at one go. That is why I was asking if
there was any built-it time() or similar function. I'm half tempted to try
to hack in a new built-in, but that is likely a heavy lift.
On Sun, Feb 9, 2025 at 5:21 PM Rudolf via Discuss <
discuss@lists.openscad.org> wrote:
If you just intend to do some runtime-tests on previews and renders (F5
and F6), you can exploit the "Total rendering time" information provided
in the console window. However don't forget to clear the cache if modules
are involved.
Am 09.02.2025 um 19:10 schrieb John David via Discuss:
I want to do a bunch of timing tests, but as far as I can tell, there are
no functions to pull the wall clock time and derive an elapse time.
Does anyone know of how to do this, or do we need to hack in a new
built-in function?
EBo --
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
I was asked to do some simple until tests for two alternatives of the
nurbs_length() function. So far I have written some simple tests, and
copy/pasted the results run one at a time. It would be nice to set up a
dozen edge cases and run them all at one go. That is why I was asking if
there was any built-it time() or similar function. I'm half tempted to try
to hack in a new built-in, but that is likely a heavy lift.
On Sun, Feb 9, 2025 at 5:21 PM Rudolf via Discuss <
discuss@lists.openscad.org> wrote:
> If you just intend to do some runtime-tests on previews and renders (F5
> and F6), you can exploit the "Total rendering time" information provided
> in the console window. However don't forget to clear the cache if modules
> are involved.
> Am 09.02.2025 um 19:10 schrieb John David via Discuss:
>
> I want to do a bunch of timing tests, but as far as I can tell, there are
> no functions to pull the wall clock time and derive an elapse time.
>
> Does anyone know of how to do this, or do we need to hack in a new
> built-in function?
>
> EBo --
>
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
JD
John David
Mon, Feb 10, 2025 8:37 PM
While focusing on elapse time, I wrote a function time([prior]) that
returns the microseconds resolution time in seconds since the epoch. If
you give it a prior time stamp, then it will return the difference in
seconds (microseconds resolution). The diff to follow. Please let me know
what you would like the API to really look like, and I will give it a go,
and send a proper pull request.
EBo --
diff --git a/src/core/builtin_functions.cc b/src/core/builtin_functions.cc
index 69d22bae5..2222123fe 100644
--- a/src/core/builtin_functions.cc
+++ b/src/core/builtin_functions.cc
@@ -47,6 +47,7 @@
#include <algorithm>
#include <random>
#include <vector>
+#include <chrono>
#include "utils/boost-utils.h"
// hash double
@@ -359,6 +360,26 @@ Value builtin_length(Arguments arguments, const
Location& loc)
return {double( arguments[0]->toStrUtf8Wrapper().get_utf8_strlen() )};
}
+Value builtin_time(Arguments arguments, const Location& loc)
+{
Value builtin_log(Arguments arguments, const Location& loc)
{
double x, y;
@@ -1085,6 +1106,12 @@ void register_builtin_functions()
"ord(string) -> number",
});
- Builtins::init("time", new BuiltinFunction(&builtin_time),
- {
- "time() -> number",
- "time(number) -> number",
- });
- Builtins::init("concat", new BuiltinFunction(&builtin_concat),
{
"concat(number or string or vector, ...) -> vector",
On Sun, Feb 9, 2025 at 8:28 PM John David ebo.2112@gmail.com wrote:
I was asked to do some simple until tests for two alternatives of the
nurbs_length() function. So far I have written some simple tests, and
copy/pasted the results run one at a time. It would be nice to set up a
dozen edge cases and run them all at one go. That is why I was asking if
there was any built-it time() or similar function. I'm half tempted to try
to hack in a new built-in, but that is likely a heavy lift.
On Sun, Feb 9, 2025 at 5:21 PM Rudolf via Discuss <
discuss@lists.openscad.org> wrote:
If you just intend to do some runtime-tests on previews and renders (F5
and F6), you can exploit the "Total rendering time" information provided
in the console window. However don't forget to clear the cache if modules
are involved.
Am 09.02.2025 um 19:10 schrieb John David via Discuss:
I want to do a bunch of timing tests, but as far as I can tell, there are
no functions to pull the wall clock time and derive an elapse time.
Does anyone know of how to do this, or do we need to hack in a new
built-in function?
EBo --
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
While focusing on elapse time, I wrote a function time([prior]) that
returns the microseconds resolution time in seconds since the epoch. If
you give it a prior time stamp, then it will return the difference in
seconds (microseconds resolution). The diff to follow. Please let me know
what you would like the API to really look like, and I will give it a go,
and send a proper pull request.
EBo --
diff --git a/src/core/builtin_functions.cc b/src/core/builtin_functions.cc
index 69d22bae5..2222123fe 100644
--- a/src/core/builtin_functions.cc
+++ b/src/core/builtin_functions.cc
@@ -47,6 +47,7 @@
#include <algorithm>
#include <random>
#include <vector>
+#include <chrono>
#include "utils/boost-utils.h"
// hash double
@@ -359,6 +360,26 @@ Value builtin_length(Arguments arguments, const
Location& loc)
return {double( arguments[0]->toStrUtf8Wrapper().get_utf8_strlen() )};
}
+Value builtin_time(Arguments arguments, const Location& loc)
+{
+ // grab the high resolution clock in us
+ auto now = std::chrono::duration_cast<std::chrono::microseconds>(
+ std::chrono::high_resolution_clock::now().time_since_epoch())
+ .count();
+
+ // it appears that you can only return doubles, so convert the
+ // microsecond clock to fractional seconds.
+ double dnow = double(now)/1000000.0;
+
+ if (arguments.size() == 1) {
+ if (!check_arguments("time", arguments, loc, { Value::Type::NUMBER }))
{
+ return Value::undefined.clone();
+ }
+ return {dnow - arguments[0]->toDouble()};
+ }
+ return {dnow};
+}
+
Value builtin_log(Arguments arguments, const Location& loc)
{
double x, y;
@@ -1085,6 +1106,12 @@ void register_builtin_functions()
"ord(string) -> number",
});
+ Builtins::init("time", new BuiltinFunction(&builtin_time),
+ {
+ "time() -> number",
+ "time(number) -> number",
+ });
+
Builtins::init("concat", new BuiltinFunction(&builtin_concat),
{
"concat(number or string or vector, ...) -> vector",
On Sun, Feb 9, 2025 at 8:28 PM John David <ebo.2112@gmail.com> wrote:
> I was asked to do some simple until tests for two alternatives of the
> nurbs_length() function. So far I have written some simple tests, and
> copy/pasted the results run one at a time. It would be nice to set up a
> dozen edge cases and run them all at one go. That is why I was asking if
> there was any built-it time() or similar function. I'm half tempted to try
> to hack in a new built-in, but that is likely a heavy lift.
>
> On Sun, Feb 9, 2025 at 5:21 PM Rudolf via Discuss <
> discuss@lists.openscad.org> wrote:
>
>> If you just intend to do some runtime-tests on previews and renders (F5
>> and F6), you can exploit the "Total rendering time" information provided
>> in the console window. However don't forget to clear the cache if modules
>> are involved.
>> Am 09.02.2025 um 19:10 schrieb John David via Discuss:
>>
>> I want to do a bunch of timing tests, but as far as I can tell, there are
>> no functions to pull the wall clock time and derive an elapse time.
>>
>> Does anyone know of how to do this, or do we need to hack in a new
>> built-in function?
>>
>> EBo --
>>
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> To unsubscribe send an email to discuss-leave@lists.openscad.org
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> To unsubscribe send an email to discuss-leave@lists.openscad.org
>>
>
JB
Jordan Brown
Tue, Feb 11, 2025 2:18 AM
One question is whether we want a function that will produce confusing
results when and if we start parallelizing execution.
Revar's suggestion of a module that times the execution of its
child(ren?) seems like it could work and be meaningful even in the face
of parallelism.
Another question is whether we want a mechanism that is useful only for
benchmarking, or one that is useful for timestamping?
One question is whether we want a function that will produce confusing
results when and if we start parallelizing execution.
Revar's suggestion of a module that times the execution of its
child(ren?) seems like it could work and be meaningful even in the face
of parallelism.
Another question is whether we want a mechanism that is useful only for
benchmarking, or one that is useful for timestamping?