omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Numpy Bench

    Pythonista
    3
    7
    4047
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • wolf71
      wolf71 last edited by

      import numpy as np
      import time
      import math
      
      bt = time.time()
      n = 1000
      for i in range(1):
      	a = np.random.uniform(low=0., high=1., size=(n, n)).astype(np.float32)
      	b = np.random.uniform(low=0., high=1., size=(n, n)).astype(np.float32)
      	a = a.dot(b)
      print ('(%d * %d),Total Time:%.3f'%(n,n,time.time()-bt))
      
      start = time.clock()
      x = [i * 0.001 for i in xrange(10000000)]
      for i, t in enumerate(x):
      	x[i] = math.sin(t)
      print ("math.sin:%.3f"%(time.clock() - start))
      
      start = time.clock()
      y = [i * 0.001 for i in xrange(10000000)]
      y = np.array(y)
      print ("numpy.sin1:%.3f"%(time.clock() - start))
      start = time.clock()
      np.sin(y,y)
      print ("numpy.sin2:%.3f"%(time.clock() - start))
      
      
      '''
      * ipad Pro 9.7 
      (1000 * 1000),Total Time:8.840
      math.sin: 3.04883
      numpy.sin: 2.668903 (2.517,0.177)
      
      =====Android Termux=====
      (1000,1000) 0.627
      math.sin: 33.899
      numpy.sin: 14.953
      
      =====MacBook Air 13 @2010====
      (1000,1000) 0.234
      math.sin: 8.95
      numpy.sin: 4.71 (3.88,0.48)
      
      ====Microsoft Surface 3 @2015====
      (1000,1000) 0.203
      math.sin: 12.739
      numpy.sin: (5.419,0.380)
      
      

      Why iOS numpy (1000,1000) very slow ???

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by JonB

        is this the same exact code run on all devices? clearly not, since the output is different

        Note the time here is the time to run random.uniform(1000,1000) twice, plus the dot product. The dot product is the time consuming bit.

        1 Reply Last reply Reply Quote 0
        • wolf71
          wolf71 last edited by

          all devices run same code.

          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            it is not the same code, since the output is different form. maybe you use * instead of .dot() for the other platfoms?

            Alternatively, perhaps the matrix multiplication is not well optimized on ios (i.e using all of the BLAS or Accelerate, etc)

            1 Reply Last reply Reply Quote 0
            • Phuket2
              Phuket2 last edited by

              I got the below from my iPad Pro 12.9' latest model and the latest beta. I ran it under 2.7 as I guess thats the target because of the use of xrange.

              (1000 * 1000),Total Time:5.750
              math.sin:2.757
              numpy.sin1:2.156
              numpy.sin2:0.131

              1 Reply Last reply Reply Quote 0
              • wolf71
                wolf71 last edited by wolf71

                iPhone X (Pythonista V3.2 , Python 2.7)

                (1000 * 1000),Total Time:6.435
                math.sin:2.250
                numpy.sin1:1.697
                numpy.sin2:0.111

                1 Reply Last reply Reply Quote 0
                • JonB
                  JonB last edited by

                  as an aside -- you shouls never create arrays like this... use np.linspace! np.linspace(0,10,1000000) is about 10x faster than list comprehension!

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors