Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    array is not better than list when the number is large and append operate

    General Discussion
    1
    1
    103
    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.
    • tianjixuetu
      tianjixuetu last edited by

      from array import array
      import numpy as np
      import time 
      # append数据
      content_append_by_array=array('d')
      content_append_by_list=list()
      # 尝试分别给每个增加10**n的数据(n从1,到11),计算时间
      # n=range(1,12)
      array_time=[]
      list_time=[]
      for i in range(1,9):
          print(i)
          t1=time.time()
          for x in range(10**i):
              content_append_by_array.append(x)
          t2=time.time()
          array_time.append(t2-t1)
          
          t1=time.time()
          for x in range(10**i):
              content_append_by_list.append(x)
          t2=time.time()
          list_time.append(t2-t1)
      import pandas as pd
      import matplotlib.pyplot as plt
      df=pd.DataFrame(index=range(1,9))
      df['array']=array_time
      df['list']=list_time
      df.plot()
      plt.show()  
      

      下载.png
      原文来自于

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors