foreach for Iterator效能對比

2021-09-03 02:25:40 字數 711 閱讀 2400

**如下

/**

* iterator,for,foreach比較

* date 2018-12-14

*/public class test

//執行完後的時間

long end =system.nanotime();

return (end- start) / (1000);

} //foeach迴圈遍歷

public static long testforeach()

//執行完後的時間

long end =system.nanotime();

return (end- start) / (1000);

} //for迴圈遍歷

public static long testfor()

$end_for_time = microtime_float();

$for_time = $end_for_time - $start_for_time;

echo 'for迴圈遍歷耗時:'.$for_time.'

';

//for迴圈遍歷(count在外部)耗時:0.023999929428101

結果:

1.10萬級資料下測試結果為foreach效能最好

2.1萬級資料下測試結果為for效能最好,且count在外部

python效能對比

1 coding utf8 import datetime road nodes for i in range 5000000 road nodes i beg time datetime.datetime.now for key,val in road nodes.items pass end t...

SSD效能對比

ssd效能測試 順序寫 16k iops 85061.08 順序寫 8k iops 146250.93 順序寫 4k iops 239816.69 順序寫 2k iops 294540.87 順序寫 1k iops 347170.06 隨機寫 16k iops 21865.24 隨機寫 8k iop...

python效能對比

閱讀目錄 回到頂部 1 coding utf8 import datetime road nodes for i in range 5000000 road nodes i beg time datetime.datetime.now for key,val in road nodes.items ...