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;
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
|
show 8 more comments
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
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 isO(log n)
where n is the n fromx ** 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
|
show 8 more comments
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
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
python python-3.x
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 isO(log n)
where n is the n fromx ** 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
|
show 8 more comments
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 isO(log n)
where n is the n fromx ** 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
|
show 8 more comments
1 Answer
1
active
oldest
votes
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
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
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 fromx ** 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