julia では println() 内の変数では、$を使って、"," を減らす方が早いようだ
今さらですが、 println() 内の変数では、$を使って、"," を減らす方が早いようです。
#1 julia> @time for animal in ["dog", "cat", "mouse"] println(animal," is a mammal") end dog is a mammal cat is a mammal mouse is a mammal 0.000147 seconds (20 allocations: 848 bytes) julia> @time for animal in ["dog", "cat", "mouse"] println("$animal is a mammal") end dog is a mammal cat is a mammal mouse is a mammal 0.000082 seconds (17 allocations: 864 bytes)
#2 julia> @time for (k, v) in Dict("dog" => "mammal", "cat" => "mammal", "mouse" => "mammal") println("$k is a $v") end mouse is a mammal cat is a mammal dog is a mammal 0.000082 seconds (23 allocations: 1.063 KiB) julia> @time for (k, v) in Dict("dog" => "mammal", "cat" => "mammal", "mouse" => "mammal") println(k," is a ",v) end mouse is a mammal cat is a mammal dog is a mammal 0.000135 seconds (35 allocations: 1.234 KiB)