SE250:lab-3:shua066

From Marks Wiki
Jump to navigation Jump to search

task 1

code

int main(){
    clock_t t0=clock();
    ArrayList xs;
    arraylist_init(&xs);
    int i;
    for(i=1; i<10000000; i++){
        arraylist_push(&xs, 10);
    }
    printf("%ld\n",clock()-t0);
    return 0;
}

result

452 436 452 436 437 421

the average is 440.8

task 2

change the factor "*2.0"

                                                average
"*3.0"   359 342 390 328 358 327 327 359 342      348
"*4.0"   265 359 358 342 312 343 311 311 327      325.3
"*5.0"   343 343 389 342 327 390 358 326 359      353
"*6.0"   327 343 327 311 327 358 311 312 265      320
"*7.0"   296 311 343 327 296 280 312 280 359      311.5
"*8.0"   266 311 296 265 249 327 311 389 343      306
"*9.0"   327 296 280 296 311 280 343 296 327      306

when the factor is bigger , the time takes shorter, and when the factor grow up to 6.0 the time change is shorter shorter.

task 3

change the restore value of ARRAYLIST_MIN_ALLOC

ARRAYLIST_MIN_ALLOC 1

468 421 389 421 405 389    ave is 415.5

ARRAYLIST_MIN_ALLOC 3

389 374 405 374 343 358    ave is 373

ARRAYLIST_MIN_ALLOC 6

342 374 359 374 327 358    ave is 355

ARRAYLIST_MIN_ALLOC 16

ave is 348 (num from task 1 above)

ARRAYLIST_MIN_ALLOC 30

389 406 374 359 389 406    ave is 387

ARRAYLIST_MIN_ALLOC 60

359 343 359 390 343 390    ave is 364

ARRAYLIST_MIN_ALLOC 100

374 374 358 343 326 343    ave is 353

ARRAYLIST_MIN_ALLOC 1000

342 405 359 375 358 405    ave is 374

ARRAYLIST_MIN_ALLOC 10000

327 280 311 343 375 374    ave is 335

ARRAYLIST_MIN_ALLOC 1000000

343 358 312 358 405 297    ave is 345.5

ARRAYLIST_MIN_ALLOC 100000000

265 281 280 280 249 311    ave is 277

ARRAYLIST_MIN_ALLOC 1000000000

result is error , number is too big

ARRAYLIST_MIN_ALLOC 10000000000

comeout lots of warnings

task 4

code

int main(){
    clock_t t0=clock();
    ArrayList xs;
    arraylist_init(&xs);
    ensure_capacity(&xs,10000000);
    int i;
    for(i=1; i<10000000; i++){
        arraylist_push(&xs, 10);
    }
    printf("%ld\n",clock()-t0);
    return 0;
}

result

312 296 342 343 264 280 265 
average is 300

task 5

change the arraylist_put replay"*2"with adding some numbers

+1000 n=1000000 push=10

31 31 15 30 46 31
average is 30.6

+10000 n=1000000 push=10

46 47 46 51 31 15
average is 39.3

+100000 n=1000000 push=10

31 46 31 15 30 16
average is 28.2

+1000000 n=1000000 push=10

31 15 31 15 63 31
average is 31

+5000000 n=1000000 push=10

15 30 31 31 46 15
average is 28

when the adding the number is bigger , the time is change up and down ,and in adding the same number(like "+1000000 n=1000000 push=10"),time is change as well, sometimes is only 15 ,and sometimes is 30, but ever sometimes it change to 63 as well , so strange.

task 6

code

int main(){
    clock_t t0=clock();
    ArrayList xs;
    arraylist_init(&xs);
    int i;
    for(i=1; i<10000000; i++){
        arraylist_put(&xs, 10,0);
    }
    printf("%ld\n",clock()-t0);
    return 0;
}

result

it takes very very long time to finish it . so , i change the number of n to 100000

3260 3198 3182 3135 3322
average is 3219