search

Home  >  Q&A  >  body text

c++ - log(x)的时间复杂度是多少?

我写的一段机器学习的代码中添加了一些功能,其中涉及到了计算信息熵,其中计算信息熵需要计算log(x),然后代码执行起来非常慢,因为这段代码中涉及到了大量的对数运算,我想知道计算机在计算log(x)的时间复杂度是多少?

迷茫迷茫2807 days ago685

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 13:48:07

    http://stackoverflow.com/questions/7317414/what-is-the-complexity-of-the-log-function

    TLDR: Modern processors have CPU instructions to directly calculate logarithms. Generally speaking, when we say time complexity, we actually refer to the number of CPU instructions, so it is O(1) (fixed number of instructions)

    reply
    0
  • PHPz

    PHPz2017-04-17 13:48:07

    Isn’t it O(1)?

    reply
    0
  • PHPz

    PHPz2017-04-17 13:48:07

    O(1), but the constant is slightly larger

    reply
    0
  • Cancelreply