Opened 11 years ago

Closed 21 months ago

#5091 closed defect (wontfix)

find_root should call fast_float

Reported by: robertwb Owned by: burcin
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: calculus Keywords:
Cc: jason Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

sage: f(x) = sin(x)-cos(x)
sage: g = f._fast_float_()

sage: timeit("find_root(f, 0, pi)")
625 loops, best of 3: 154 µs per loop

sage: timeit("find_root(g, 0, pi)")
625 loops, best of 3: 24 µs per loop

See also http://groups.google.com/group/sage-devel/browse_thread/thread/927319a4fa61ae3b/9fc80aa9c114e041

Change History (13)

comment:1 Changed 11 years ago by mabshoff

  • Milestone changed from sage-3.4 to sage-3.4.1

3.4 is for ReST tickets only.

Cheers,

Michael

comment:2 Changed 11 years ago by jason

  • Cc jason added

comment:3 Changed 10 years ago by wcauchois

Incorporating the time it takes to call fast_float, the speedup is not that radical:

sage: var('x')
x
sage: from sage.ext.fast_eval import fast_float
sage: timeit("find_root(sin(x)-cos(x), 0, pi)")
625 loops, best of 3: 441 µs per loop
sage: timeit("find_root(fast_float(sin(x)-cos(x), x), 0, pi)")
625 loops, best of 3: 393 µs per loop

Its better for clients to call fast_float themselves, if they're using find_root inside a loop.

comment:4 Changed 10 years ago by jason

  • Report Upstream set to N/A

There is a small speedup here, so why not call it?

comment:5 Changed 10 years ago by robertwb

The point is that there should be a big speedup--I'm going to try and track down why construction is so expensive.

comment:6 Changed 6 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:7 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:8 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:9 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:10 Changed 3 years ago by rws

  • Milestone changed from sage-6.4 to sage-duplicate/invalid/wontfix
  • Status changed from new to needs_review

Actually the speedup is 13x here (Sage 7.5beta5) only if the fast float already exists.

sage: timeit("find_root(f, 0, pi)")
625 loops, best of 3: 131 µs per loop
sage: timeit("find_root(g, 0, pi)")
625 loops, best of 3: 10.2 µs per loop
sage: timeit("find_root(sin(x)-cos(x), 0, pi)")
625 loops, best of 3: 170 µs per loop
sage: timeit("find_root(fast_float(sin(x)-cos(x), x), 0, pi)")
625 loops, best of 3: 161 µs per loop

sage: timeit('_ = sin(x)-cos(x)')
625 loops, best of 3: 9.3 µs per loop
sage: timeit("_ = fast_float(sin(x)-cos(x), x)")
625 loops, best of 3: 140 µs per loop

The creation of sin(x)-cos(x) takes 10µs, find_root of a fast float takes also 10µs. What is slow is creation of the fast float (130µs) and find_root of the normal expression (120µs). So there is no gain converting to fast float because conversion eats it all.

Therefore I propose to close this ticket.

comment:11 Changed 2 years ago by kcrisman

Sounds reasonable to me. Nice hunting.

comment:12 Changed 22 months ago by chapoton

  • Status changed from needs_review to positive_review

comment:13 Changed 21 months ago by embray

  • Resolution set to wontfix
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.