然而,我建议不要使用优雅的 Brads 自定义方法。它比设置和比较局部变量要慢。
local(
timer,
loops = 1000,
present_value,
prev_value,
out = string,
result = string
)
inline(-database = 'mysql', -sql = "SELECT * FROM help_category") => {
#timer = micros
loop(#loops) => {
rows => {
#present_value = field('name')
#prev_value != #present_value ? #out -> append('<hr />Here be a new field<br />')
#out -> append(#present_value + '<br />')
#prev_value = #present_value
}
}
#result -> append('Result using local ' + ((micros - #timer) / # loops) + '<br />')
#timer = micros
loop(#loops) => {
rows => {
#present_value = field('name')
loop_count > 1 and #prev_value != fieldFromRow(#present_value, loop_count -1) ? #out -> append('<hr />Here be a new field<br />')
#out -> append(#present_value + '<br />')
}
}
#result -> append('Result using fieldFromRow ' + ((micros - #timer) / # loops) + '<br />')
}
#result
-> 结果使用本地 637
结果使用 fieldFromRow 1612