Working on *why* it might be so slow a bit:

%prun for i in range(100r): f(0.1)
         798103 function calls (791903 primitive calls) in 1.327 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     8000    0.556    0.000    0.628    0.000 maxima_lib.py:438(_eval_line)
      100    0.299    0.003    1.318    0.013 piecewise.py:188(_subs_)
    16000    0.059    0.000    0.067    0.000 {method 'random_element' of 
'sage.rings.real_mpfi.RealIntervalField_class' objects}
     1700    0.054    0.000    0.060    0.000 
maxima_lib.py:298(max_to_string)
   232200    0.032    0.000    0.048    0.000 calculus.py:2204(_is_function)
      900    0.028    0.000    0.050    0.000 calculus.py:2319(<dictcomp>)
     2700    0.024    0.000    0.024    0.000 {built-in method 
sage.libs.ecl.ecl_eval}
      900    0.021    0.000    0.047    0.000 calculus.py:2317(<dictcomp>)
   273700    0.018    0.000    0.018    0.000 {built-in method 
builtins.isinstance}
      900    0.015    0.000    0.033    0.000 {method 'parse_sequence' of 
'sage.misc.parser.Parser' objects}

so, most stuff is happening in maxima and in _subs_, and somehow random 
elements of an intervalfield are needed ...
I don't think the design was primarily focused on numerical evaluation 
speed but rather on having symbolic piecewise functions.
On Wednesday 1 May 2024 at 06:38:36 UTC-7 David Joyner wrote:

> For another data point, on an ubuntu laptop:
>
> sage: time [f(0.1*i) for i in range(1,10)]
> CPU times: user 136 ms, sys: 0 ns, total: 136 ms
> Wall time: 99.1 ms
> [1, 1, 1, 1, 1, 1, 1, 1, 1]
> sage: time f(0.1)
> CPU times: user 13.6 ms, sys: 0 ns, total: 13.6 ms
> Wall time: 13.5 ms
> 1
> sage: version()
> 'SageMath version 10.3.rc1, Release Date: 2024-02-29'
>
> On Wed, May 1, 2024 at 5:21 AM Kwankyu Lee <ekwa...@gmail.com> wrote:
> >
> > Hi,
> >
> > I get
> >
> > sage: f = piecewise([((0,1),1)])
> > sage: time f(0.1)
> > CPU times: user 135 ms, sys: 4.23 ms, total: 140 ms
> > Wall time: 146 ms
> > 1
> > sage: time f(0.2)
> > CPU times: user 133 ms, sys: 3.56 ms, total: 136 ms
> > Wall time: 137 ms
> > 1
> >
> > This is painfully slow. Is this normal?
> >
> > --
> > You received this message because you are subscribed to the Google 
> Groups "sage-devel" group.
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to sage-devel+...@googlegroups.com.
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sage-devel/af2161ba-1ee9-4636-9cea-98ea6031796bn%40googlegroups.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/e01afcef-943f-4f58-8978-882f807f763en%40googlegroups.com.

Reply via email to