Skip to content

Some benchmarks of memory and runtime performance of Scala's collections

Notifications You must be signed in to change notification settings

rgwilton/scala-bench

 
 

Repository files navigation

scala-bench

Some benchmarks of memory and runtime performance of Scala's collections

Clone of Li Haoyi's version.

Moved to Scala 2.12.3 & sbt 1.0. Increased work in tests to make array's a fairer comparision. Changed results to be amortized per element (times should be nano-seconds). Added some extra tests for updating arrays.

These are informal results from running on my laptop. Times are amortized per element times (should be in nano-seconds).

Size 1 4 16 64 256 1024 4096 16192 65536 262144 1048576
construct
List 56 28 19 21 24 27 26 27 30 29 86
Vector 171 119 144 161 161 156 163 161 176 169 183
Set 89 132 922 667 712 853 1038 1083 1291 1578 1777
Map 94 202 731 689 740 831 1039 1141 1199 1461 1645
Array:+ 144 109 109 124 275 829 2646 14624
Array-prealloc 108 34 15 12 11 11 10 11 11 11 12
Array.toSet 460 213 523 669 745 810 1023 1009 1259 1551 1740
Array.toVector 577 156 62 52 41 41 40 38 41 39 41
Array.toMap 202 184 562 759 728 771 981 1073 1246 1544 1746
TreeMap (int) 175 237 341 477 681 931 1096 1204 1363 1609 1852
TreeMap (string) 242 265 459 601 1071 1196 1595 1625 1831 2185 2444
m.Buffer 250 114 93 86 86 83 85 90 84 85 87
m.Set 459 310 402 424 453 471 456 466 526 711 792
m.Map 397 339 447 505 474 515 521 540 699 901 1035
foreach (*10)
List 10 7 6 8 8 9 9 9 9 11 11
List-while 5 9 8 9 8 9 9 9 9 11 12
Vector 110 29 12 13 13 13 13 13 13 15 15
Vector-while 20 7 5 11 10 11 14 14 20 23 24
TreeMap (int) 25 33 26 24 25 32 48 58 128 136 57
TreeMap (string) 61 35 28 26 28 34 50 63 122 126 140
Set 6 1 20 20 18 29 48 51 113 122 188
Map 20 16 22 21 21 32 51 68 141 129 188
Array 18 7 4 4 3 3 3 3 2 2 3
Array-while 13 6 3 3 2 1 2 2 2 1 2
m.Buffer 17 6 4 3 3 3 3 3 3 3 3
m.Set 73 19 11 10 10 9 28 43 45 46 45
m.Map 105 59 39 34 35 33 65 88 98 112 126
lookup (*10)
List 3 3 9 46 207 901 4001 16418
Vector 5 2 2 2 2 2 3 4 5 7 6
Set 3 8 17 18 23 29 38 54 104 126 179
Map 3 9 18 19 24 34 39 65 95 112 135
TreeMap (int) 18 18 22 23 50 62 75 102 114 134 131
TreeMap (string) 12 10 12 16 45 95 114 143 170 167 187
Array 2 1 1 1 1 1 1 1 1 1 1
m.Buffer 4 1 1 1 1 1 1 1 1 1 1
m.Set 87 89 61 96 96 92 90 106 125 121 128
m.Map 10 9 9 10 10 12 15 18 34 38 44
immutable update (replace)
Vector 167 111 106 141 141 109 487 481 629 615 619
Map 77 87 312 445 562 698 802 1110 1310 1536 10044
TreeMap (int) 94 159 247 419 550 781 1071 1227 1298 1530 1698
TreeMap (string) 235 260 403 526 738 1080 1343 1585 1717 2000 2410
Array (copy) 101 52 42 84 323 1412 5225
mutable update
Array (in place) 61 21 13 10 10 9 10 10 10 10 11
immutable update (insert)
Vector 2937 2330 2234 2164 2246 2165 2223 2256 2205 2256 2205
Map 86 476 281 398 506 632 766 973 1248 1441 2392
TreeMap (int) 196 309 449 486 698 998 1107 1280 1409 1481 1770
TreeMap (string) 284 343 483 657 899 1283 1490 1799 1930 2183 2723

About

Some benchmarks of memory and runtime performance of Scala's collections

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 100.0%