Efficiency analysis Schwartzian transform
while shorter code, naive approach here less efficient if key function (called foo in example above) expensive compute. because code inside brackets evaluated each time 2 elements need compared. optimal comparison sort performs o(n log n) comparisons (where n length of list), 2 calls foo every comparison, resulting in o(n log n) calls foo. in comparison, using schwartzian transform, make 1 call foo per element, @ beginning map stage, total of n calls foo.
however, if function foo relatively simple, overhead of schwartzian transform may unwarranted.
Comments
Post a Comment