hi guys!
Thus anyone know how to put timer in bubble sort using javascript???

I am trying to make a timer for my sort but I can't make it. I don't know how to connect...

heres my work..

<html>
<head>
<title>sortBubble</title>
</head>
<script>
<!-- Begin
var myArray = new Array(102,201,3,517,77,345,68,234,8,9,4,517,6,0)

function bubbleSort(ns,test) {
ts=new Date();
j=0;i=0;//test='>'
//alert(myArray)
//ns = myArray
//

alert("Sorted array: \n"+ns)
alert("time to sort =\n"+(ts)+" milliseconds")
}
// End -->
</script>

<body onLoad="bubbleSort(myArray,'<');">


</body>
</html>

<vent>Tell your instructor that at least one highly experienced coder thinks he should be fired. Asking students to code a bubble (or other) sort is absurd. Sort algorithms are non-trivial but fully explored. In any modern language you call a 'sort()' method and you will never have to code a sort.</vent>

Now to your question. You time anything by a) finding a nice tester (Google) or b) writing your own. Option b can be trivial. Untested code:

var start = new Date();
do routine_to_be_timed();
alert( new Date() - start );
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.