更新时间:2023-12-06 15:57:46
我认为,如果您将名称作为元数据添加到节点,并且在每次比较时都无需查看DOM,它将更快.记住,毕竟它们是O(n 2 ).
I think if you add name as metadata to the node and eliminate looking through the DOM on every comparison, it'll be much faster. Remember, there's O(n2) of them after all.
$(function() {
$('.media-status-specie li')
.each(function () {
$(this).data('name', $(this).find(".english").text());
})
});
....
function sortDescending1(a, b) {
return $(a).data('name') < $(b).data('name') ? 1 : -1;
}
免责声明:我认为,与其他任何开发人员一样,我不擅长猜测慢点,而是使用探查器来找到真正的性能杀手.
Disclaimer: It's my opinion, I'm no good at guessing slow points as any other developer out there, use profiler to find real performance killer.