Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/wikka.php on line 315 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/libs/Wakka.class.php on line 176 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/libs/Wakka.class.php on line 463 Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/demetres/public_html/didattica/ae/wikka.php on line 120 Deprecated: Function ereg() is deprecated in /home/demetres/public_html/didattica/ae/libs/Wakka.class.php on line 648 Ingegneria degli Algoritmi: Prestazioni accesso sequenziale a file

Ingegneria degli Algoritmi

Corso di Laurea in Ingegneria Informatica e Automatica - A.A. 2014-2015

HomePage | Avvisi | Diario lezioni | Programma | Materiale didattico | Esami | Forum | Login
Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/safehtml.php on line 308 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 159 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 161 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 162 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 163 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 165 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 166 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 167 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 243 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 250 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 259 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 266 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 273 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 280 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 467 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 469 Deprecated: Assigning the return value of new by reference is deprecated in /home/demetres/public_html/didattica/ae/3rdparty/core/safehtml/classes/HTMLSax.php on line 471

Prestazioni accesso sequenziale a file


Programma per la creazione di un file contenente N interi casuali a 32 bit:

MakeRandFile.c
#include <stdio.h>
#include <stdlib.h>

/* type of file items */
typedef unsigned long ItemType;

int main(int argc, char** argv){

    FILE* f;
    long long N, i;
   
    /* check command line parameters */
    if (argc < 3) exit (printf("Usage: ./MakeRandFile fileName numItems\n"));
   
    /* convert number of items from string to integer format */
    N = atoll(argv[2]);
   
    printf("file offset: %d bit\n", (int)sizeof(off_t)*8);
    printf("creating random file of %lld 32 bit integers...\n", N);
   
    /* open file for writing */
    f = fopen(argv[1], "w+");
    if (f == NULL) exit(printf("can't open file\n"));

    /* make N sequential file accesses */
    for (i=0; i<N; ++i) {
        ItemType val = rand();
        fwrite(&val, sizeof(ItemType), 1, f);
    }

    fclose(f);
}


Analisi sperimentale

Obiettivo: stimare il tempo di scrittura sequenziale di un file di 2 miliardi di interi a 32 bit (7.45 GB)

Piattaforma:


Esperimento:

> gcc -o MakeRandFile MakeRandFile.c
> time ./MakeRandFile large.dat 2000000000
file offset: 64 bit
creating random file of 2000000000 32 bit integers...

real	4m10.685s
user	2m43.309s
sys	0m43.362s
>


Risultati:

Il tempo richiesto per generare sequenzialmente un file di 2 miliardi di interi a 32 bit (7.45 GB) è di 4 minuti e 10.685 secondi = 250.685 secondi, cioè 120 nanosecondi per intero, ovvero un throughput di circa 31.8 MB/sec.

L'uso della CPU durante l'esecuzione del programma si attesta intorno al 77%.

Si confrontino questi risultati con l'accesso casuale a file.



Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.3
Page was generated in 0.0517 seconds