13
$\begingroup$

Backslide introduced in 12.0, persisting through 13.1.


Recently I noticed that the big integer calculation of the new version is much slower than the old version, can you reproduce, is there a way to speed up in the new version?

#^2 (#^2 + 1) &@Range[10^6]; // AbsoluteTiming

enter image description here


A short history of performance changes throughout Mathematica versions on Linux:

Linux 8.0.4:

In[]:= #^2 (#^2 + 1) &@Range[10^6]; // AbsoluteTiming                          

Out[]= {0.730327, Null}

Linux 9.0.1 and 10.0.2 get faster:

In[]:= #^2 (#^2 + 1) &@Range[10^6]; // AbsoluteTiming                          

Out[]= {0.256588, Null}

Linux 10.1 gets faster:

In[]:= #^2 (#^2 + 1) &@Range[10^6]; // AbsoluteTiming                          
                                                                                
Out[]= {0.138035, Null}

11.3 gets very slightly faster:

In[]:= #^2 (#^2 + 1) &@Range[10^6]; // AbsoluteTiming                          

Out[]= {0.110871, Null}

12.0 gets much slower:

In[]:= #^2 (#^2 + 1) &@Range[10^6]; // AbsoluteTiming                          
                                                                                
Out[]= {2.00058, Null}

12.1 gets even slower:

In[]:= #^2 (#^2 + 1) &@Range[10^6]; // AbsoluteTiming                          
                                                                                
Out[]= {2.54884, Null}

This performance doesn't change up to 13.0.

$\endgroup$
5
  • 2
    $\begingroup$ I think the problem might be that the computation cannot be done with machine integers and that auto-compilation therefore fails. Or something like that. It seems like V9.0 handled that more efficiently. I think using FunctionCompile to create a function that takes "UnsignedInteger128" argument would be your best bet. $\endgroup$ Commented Jun 27, 2022 at 9:08
  • 3
    $\begingroup$ I think it's worth reporting. Have you reported this to WRI? $\endgroup$
    – xzczd
    Commented Jun 27, 2022 at 12:46
  • $\begingroup$ @xzczd Already reported. $\endgroup$
    – expression
    Commented Jun 27, 2022 at 12:54
  • 1
    $\begingroup$ Reporting as a bug. If you provide the tracking number from Tech Support I can get that info linked into the report. $\endgroup$ Commented Jun 27, 2022 at 17:40
  • $\begingroup$ Is it even slower in 13.2? It is 5.33173 here. $\endgroup$ Commented Jan 29, 2023 at 0:06

1 Answer 1

5
$\begingroup$

I think the best you can do, is to compile a function for BigInts with FunctionCompile. The compilation is slow, but the execution is fast:

fun = FunctionCompile[
  Function[Typed[arg, "ListVector"["Integer128"]], 
   Map[#^2 (#^2 + 1) &, arg]]  
];

fun @ Range[10^6]; // AbsoluteTiming

{0.208568, Null}

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.