Why is print(456 ** 5582) so fast in python?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?Behaviour of increment and decrement operators in PythonHow to copy a dictionary and only edit the copyDoes Python have a string 'contains' substring method?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?

Is it normal practice to screen share with a client?

AC contactor 1 pole or 2?

Does the Intel 8086 CPU have user mode and kernel mode?

How to Create an Image for Cantor's *Diagonal Argument* with a Diagonal Oval

401(k) investment after being fired. Do I own it?

Why did so many MPs not vote in Meaningful Vote 3?

How to deal with a player who makes bad characters and kills them?

Why is drive/partition number still used?

How to judge a Ph.D. applicant that arrives "out of thin air"

Why isn't there a serious attempt at creating a third mass-appeal party in the US?

Integral of the integral using NIntegrate

How to change the font style (not the size but the style) of algorithimc package

How much were the LMs maneuvered to their landing points?

Can I make a matrix from just a parts of the cells?

kids pooling money for Lego League and taxes

Is dd if=/dev/urandom of=/dev/mem safe?

Heisenberg uncertainty principle in daily life

Character is called by their first initial. How do I write it?

Can the term divorcée apply if a woman has not only divorced, but subsequently remarried?

"I you already know": is this proper English?

Expansion with *.txt in the shell doesn't work if no .txt file exists

What does コテッと mean?

Inadvertently nuked my disk permission structure - why?

How can I stop myself from micromanaging other PCs' actions?



Why is print(456 ** 5582) so fast in python?


Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?Behaviour of increment and decrement operators in PythonHow to copy a dictionary and only edit the copyDoes Python have a string 'contains' substring method?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















I've tried many numbers but it runs in like O(1) time. Why is this so fast? Can someone please explain how ** operator actually works.










share|improve this question



















  • 4





    probably square-and-multiply? how fast is it? what were you expecting? O(1) with respect to what?

    – hiro protagonist
    Mar 26 at 17:43







  • 1





    Many numbers? Try print(456546 ** 95675582) :)

    – tsul
    Mar 26 at 17:47






  • 1





    What do you mean by "it runs in like O(1) time?" We understand that this means constant time, but constant with respect to what? In my quick test it clearly does not scale at constant time.

    – juanpa.arrivillaga
    Mar 26 at 17:48







  • 2





    I believe the previous commenters meant that python may be using this: en.wikipedia.org/wiki/Exponentiation_by_squaring which is O(log n) where n is the n from x ** n

    – Kevin Wang
    Mar 26 at 17:49






  • 3





    This reminds me of one professor saying in his lecture "Let N be an arbitrary large number.... No, way, N is too big, let it be M instead". What was it about though.. Ah, right. O(1) algorithm can run million of years. The big-O notation is a measure of how the algorithm running is scaling with the different size inputs and not about the absolute running time.

    – Eugene Sh.
    Mar 26 at 17:51


















-1















I've tried many numbers but it runs in like O(1) time. Why is this so fast? Can someone please explain how ** operator actually works.










share|improve this question



















  • 4





    probably square-and-multiply? how fast is it? what were you expecting? O(1) with respect to what?

    – hiro protagonist
    Mar 26 at 17:43







  • 1





    Many numbers? Try print(456546 ** 95675582) :)

    – tsul
    Mar 26 at 17:47






  • 1





    What do you mean by "it runs in like O(1) time?" We understand that this means constant time, but constant with respect to what? In my quick test it clearly does not scale at constant time.

    – juanpa.arrivillaga
    Mar 26 at 17:48







  • 2





    I believe the previous commenters meant that python may be using this: en.wikipedia.org/wiki/Exponentiation_by_squaring which is O(log n) where n is the n from x ** n

    – Kevin Wang
    Mar 26 at 17:49






  • 3





    This reminds me of one professor saying in his lecture "Let N be an arbitrary large number.... No, way, N is too big, let it be M instead". What was it about though.. Ah, right. O(1) algorithm can run million of years. The big-O notation is a measure of how the algorithm running is scaling with the different size inputs and not about the absolute running time.

    – Eugene Sh.
    Mar 26 at 17:51














-1












-1








-1


1






I've tried many numbers but it runs in like O(1) time. Why is this so fast? Can someone please explain how ** operator actually works.










share|improve this question
















I've tried many numbers but it runs in like O(1) time. Why is this so fast? Can someone please explain how ** operator actually works.







python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 17:45









Patrick Artner

29.1k6 gold badges26 silver badges45 bronze badges




29.1k6 gold badges26 silver badges45 bronze badges










asked Mar 26 at 17:41









VishnuVSVishnuVS

5223 silver badges14 bronze badges




5223 silver badges14 bronze badges







  • 4





    probably square-and-multiply? how fast is it? what were you expecting? O(1) with respect to what?

    – hiro protagonist
    Mar 26 at 17:43







  • 1





    Many numbers? Try print(456546 ** 95675582) :)

    – tsul
    Mar 26 at 17:47






  • 1





    What do you mean by "it runs in like O(1) time?" We understand that this means constant time, but constant with respect to what? In my quick test it clearly does not scale at constant time.

    – juanpa.arrivillaga
    Mar 26 at 17:48







  • 2





    I believe the previous commenters meant that python may be using this: en.wikipedia.org/wiki/Exponentiation_by_squaring which is O(log n) where n is the n from x ** n

    – Kevin Wang
    Mar 26 at 17:49






  • 3





    This reminds me of one professor saying in his lecture "Let N be an arbitrary large number.... No, way, N is too big, let it be M instead". What was it about though.. Ah, right. O(1) algorithm can run million of years. The big-O notation is a measure of how the algorithm running is scaling with the different size inputs and not about the absolute running time.

    – Eugene Sh.
    Mar 26 at 17:51













  • 4





    probably square-and-multiply? how fast is it? what were you expecting? O(1) with respect to what?

    – hiro protagonist
    Mar 26 at 17:43







  • 1





    Many numbers? Try print(456546 ** 95675582) :)

    – tsul
    Mar 26 at 17:47






  • 1





    What do you mean by "it runs in like O(1) time?" We understand that this means constant time, but constant with respect to what? In my quick test it clearly does not scale at constant time.

    – juanpa.arrivillaga
    Mar 26 at 17:48







  • 2





    I believe the previous commenters meant that python may be using this: en.wikipedia.org/wiki/Exponentiation_by_squaring which is O(log n) where n is the n from x ** n

    – Kevin Wang
    Mar 26 at 17:49






  • 3





    This reminds me of one professor saying in his lecture "Let N be an arbitrary large number.... No, way, N is too big, let it be M instead". What was it about though.. Ah, right. O(1) algorithm can run million of years. The big-O notation is a measure of how the algorithm running is scaling with the different size inputs and not about the absolute running time.

    – Eugene Sh.
    Mar 26 at 17:51








4




4





probably square-and-multiply? how fast is it? what were you expecting? O(1) with respect to what?

– hiro protagonist
Mar 26 at 17:43






probably square-and-multiply? how fast is it? what were you expecting? O(1) with respect to what?

– hiro protagonist
Mar 26 at 17:43





1




1





Many numbers? Try print(456546 ** 95675582) :)

– tsul
Mar 26 at 17:47





Many numbers? Try print(456546 ** 95675582) :)

– tsul
Mar 26 at 17:47




1




1





What do you mean by "it runs in like O(1) time?" We understand that this means constant time, but constant with respect to what? In my quick test it clearly does not scale at constant time.

– juanpa.arrivillaga
Mar 26 at 17:48






What do you mean by "it runs in like O(1) time?" We understand that this means constant time, but constant with respect to what? In my quick test it clearly does not scale at constant time.

– juanpa.arrivillaga
Mar 26 at 17:48





2




2





I believe the previous commenters meant that python may be using this: en.wikipedia.org/wiki/Exponentiation_by_squaring which is O(log n) where n is the n from x ** n

– Kevin Wang
Mar 26 at 17:49





I believe the previous commenters meant that python may be using this: en.wikipedia.org/wiki/Exponentiation_by_squaring which is O(log n) where n is the n from x ** n

– Kevin Wang
Mar 26 at 17:49




3




3





This reminds me of one professor saying in his lecture "Let N be an arbitrary large number.... No, way, N is too big, let it be M instead". What was it about though.. Ah, right. O(1) algorithm can run million of years. The big-O notation is a measure of how the algorithm running is scaling with the different size inputs and not about the absolute running time.

– Eugene Sh.
Mar 26 at 17:51






This reminds me of one professor saying in his lecture "Let N be an arbitrary large number.... No, way, N is too big, let it be M instead". What was it about though.. Ah, right. O(1) algorithm can run million of years. The big-O notation is a measure of how the algorithm running is scaling with the different size inputs and not about the absolute running time.

– Eugene Sh.
Mar 26 at 17:51













1 Answer
1






active

oldest

votes


















6














The claim that this is O(1) is incorrect.



>>> %timeit 456**558 
6.22 µs ± 9.22 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
>>> %timeit 456**5582
237 µs ± 226 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)
>>> %timeit 456**55822
9.54 ms ± 13.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)


See here for the CPython implementation.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55363269%2fwhy-is-print456-5582-so-fast-in-python%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    The claim that this is O(1) is incorrect.



    >>> %timeit 456**558 
    6.22 µs ± 9.22 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
    >>> %timeit 456**5582
    237 µs ± 226 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)
    >>> %timeit 456**55822
    9.54 ms ± 13.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)


    See here for the CPython implementation.






    share|improve this answer





























      6














      The claim that this is O(1) is incorrect.



      >>> %timeit 456**558 
      6.22 µs ± 9.22 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
      >>> %timeit 456**5582
      237 µs ± 226 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)
      >>> %timeit 456**55822
      9.54 ms ± 13.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)


      See here for the CPython implementation.






      share|improve this answer



























        6












        6








        6







        The claim that this is O(1) is incorrect.



        >>> %timeit 456**558 
        6.22 µs ± 9.22 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
        >>> %timeit 456**5582
        237 µs ± 226 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)
        >>> %timeit 456**55822
        9.54 ms ± 13.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)


        See here for the CPython implementation.






        share|improve this answer















        The claim that this is O(1) is incorrect.



        >>> %timeit 456**558 
        6.22 µs ± 9.22 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
        >>> %timeit 456**5582
        237 µs ± 226 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each)
        >>> %timeit 456**55822
        9.54 ms ± 13.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)


        See here for the CPython implementation.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 26 at 18:05

























        answered Mar 26 at 17:49









        wimwim

        178k59 gold badges352 silver badges477 bronze badges




        178k59 gold badges352 silver badges477 bronze badges


















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55363269%2fwhy-is-print456-5582-so-fast-in-python%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript