none
rendimiento RRS feed

  • Pregunta

  • Hola
    ¿Hay alguna diferencia de rendimiento por usar Arrays en vez de colecciones?
    gracias


    Modifico para concretar un poco: me refiero al añadir, recuperar o modificar datos. Estoy hablando de varios Arrays o colecciones de unos 30.000 datos cada uno, de los tipos float, DateTime y String.
    viernes, 11 de mayo de 2007 7:58

Respuestas

  • Creo que estro reponde a tu pregunta:

     

    How to choose between arrays and collections

    Arrays are the fastest of all collection types, so unless you need special functionalities like dynamic extension of the collection, sorting, and searching, you should use arrays. If you need a collection type, choose the most appropriate type based on your functionality requirements to avoid performance penalties.

    • Use ArrayList to store custom object types and particularly when the data changes frequently and you perform frequent insert and delete operations. Avoid using ArrayList for storing strings.
    • Use a StringCollection to store strings.
    • Use a Hashtable to store a large number of records and to store data that may or may not change frequently. Use Hashtable for frequently queried data such as product catalogs where a product ID is the key.
    • Use a HybridDictionary to store frequently queried data when you expect the number of records to be low most of the time with occasional increases in size.
    • Use a ListDictionary to store small amounts of data (fewer than 10 items).
    • Use a NameValueCollection to store strings of key-value pairs in a presorted order. Use this type for data that changes frequently where you need to insert and delete items regularly and where you need to cache items for fast retrieval.
    • Use a Queue when you need to access data sequentially (first in is first out) based on priority.
    • Use a Stack in scenarios where you need to process items in a last–in, first-out manner.
    • Use a SortedList for fast object retrieval using an index or key. However, avoid using a SortedList for large data changes because the cost of inserting the large amount of data is high. For large data changes, use an ArrayList and then sort it by calling the Sort method.

    For more information, see "Arrays" and "Collection Guidelines" in Chapter 5, "Improving Managed Code Performance."

     

    Salu2

     

    Colabora con el foro: Si la respuesta te es de utilidad marca la pregunta como respondida.

    Luis Ruiz Pavón

    MCP

    Blog: http://geeks.ms/blogs/lruiz

    viernes, 11 de mayo de 2007 8:05

Todas las respuestas

  • Creo que estro reponde a tu pregunta:

     

    How to choose between arrays and collections

    Arrays are the fastest of all collection types, so unless you need special functionalities like dynamic extension of the collection, sorting, and searching, you should use arrays. If you need a collection type, choose the most appropriate type based on your functionality requirements to avoid performance penalties.

    • Use ArrayList to store custom object types and particularly when the data changes frequently and you perform frequent insert and delete operations. Avoid using ArrayList for storing strings.
    • Use a StringCollection to store strings.
    • Use a Hashtable to store a large number of records and to store data that may or may not change frequently. Use Hashtable for frequently queried data such as product catalogs where a product ID is the key.
    • Use a HybridDictionary to store frequently queried data when you expect the number of records to be low most of the time with occasional increases in size.
    • Use a ListDictionary to store small amounts of data (fewer than 10 items).
    • Use a NameValueCollection to store strings of key-value pairs in a presorted order. Use this type for data that changes frequently where you need to insert and delete items regularly and where you need to cache items for fast retrieval.
    • Use a Queue when you need to access data sequentially (first in is first out) based on priority.
    • Use a Stack in scenarios where you need to process items in a last–in, first-out manner.
    • Use a SortedList for fast object retrieval using an index or key. However, avoid using a SortedList for large data changes because the cost of inserting the large amount of data is high. For large data changes, use an ArrayList and then sort it by calling the Sort method.

    For more information, see "Arrays" and "Collection Guidelines" in Chapter 5, "Improving Managed Code Performance."

     

    Salu2

     

    Colabora con el foro: Si la respuesta te es de utilidad marca la pregunta como respondida.

    Luis Ruiz Pavón

    MCP

    Blog: http://geeks.ms/blogs/lruiz

    viernes, 11 de mayo de 2007 8:05
  • Gracias Luis, responde perfectamente
    viernes, 11 de mayo de 2007 8:08
  • Hola Ender:

     

    No hay de que, te dejo un enlace sobre buenas practicas que te va a gustar:

     

    Performance Best Practices at a Glance

     

    Colabora con el foro: Si la respuesta te es de utilidad marca la pregunta como respondida.

    Luis Ruiz Pavón

    MCP

    Blog: http://geeks.ms/blogs/lruiz

    viernes, 11 de mayo de 2007 8:37