11-01-2023

whereIn - integer TIP

Laravel Tip: Instead of using the ๐˜„๐—ต๐—ฒ๐—ฟ๐—ฒ๐—œ๐—ป() method to load a large range of data when the targeted value is an integer, use ๐˜„๐—ต๐—ฒ๐—ฟ๐—ฒ๐—œ๐—ป๐˜๐—ฒ๐—ด๐—ฒ๐—ฟ๐—œ๐—ป๐—ฅ๐—ฎ๐˜„() which is faster than ๐˜„๐—ต๐—ฒ๐—ฟ๐—ฒ๐—œ๐—ป().

Benchmark::measure([ 
fn() => User::whereIn('id', range(1,500))->get(), 
fn() => User::whereIntegerInRaw('id', range(1,500))->get() 
], 3) 

Run 3 times. 
Result: 
5.80 0.86 
4.30 1.69 
3.08 0.92

© 2024 PappZ. All rights reserved.