Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 02-10-2004, 08:15 PM   #1 (permalink)
Free Mars!
 
feelgood's Avatar
 
Location: I dunno, there's white people around me saying "eh" all the time
[Java + C] Merge Sort

Why is it that when I looked at the merge sort source code provided by several sorting alogrithms websites that contains a "Thread.sleep(something)" which whenever I use it, the merge sorter actually runs longer than insertion, selection or even bubble!

So, when I removed the Thread.sleep() part, the merge sort alogrithms just zip by as if it was never there while the thread.sleep is still there, it runs like its a friggin turttle...

I know its because of the Thread.sleep() but comon, why is it even there in the first place??
__________________
Looking out the window, that's an act of war. Staring at my shoes, that's an act of war. Committing an act of war? Oh you better believe that's an act of war
feelgood is offline  
Old 02-10-2004, 08:29 PM   #2 (permalink)
Junkie
 
Location: San Francisco
I have no idea...if you're trying to make a fast sort the last thing you want to do is take it off the CPU completely. The only thing I can think of is that the sort could take a long time...and that could be bad on an OS with cooperative multitasking?!?! Does Java even run on any of those?
__________________
"Prohibition will work great injury to the cause of temperance. It is a species of intemperance within itself, for it goes beyond the bounds of reason in that it attempts to control a man's appetite by legislation, and makes a crime out of things that are not crimes. A Prohibition law strikes a blow at the very principles upon which our government was founded." --Abraham Lincoln
n0nsensical is offline  
Old 02-10-2004, 08:54 PM   #3 (permalink)
Free Mars!
 
feelgood's Avatar
 
Location: I dunno, there's white people around me saying "eh" all the time
Java runs on pretty much anything it wants to...

I went back to the mergeSort alogrithms which is from the Microsystems and I found that mergeSort implemented a superclass that contained a method called "pause", and when I traced the pause back to the superclass and found that there was a Thread.sleep(20); line within the pause() method. I know that merge sort is one of the fastest sorter when it comes to large list but when I tested it on my machine, it just lagged like shit. So, I removed the thread and now..it runs like a beauty...

Just strange to see that Microsystem is even using Thread.sleep() line within a mergeSort...

While we're on the top of sorting alogrithms, I was messing around with Shell Sort and I noticed that as you increase the increments, the sorter is faster and so I just had the increment to match with the length of the array/vector and it runs at the fastest. So..just a tip for those of you who use a shell sort. Have the increment match the length of array or vector.
__________________
Looking out the window, that's an act of war. Staring at my shoes, that's an act of war. Committing an act of war? Oh you better believe that's an act of war
feelgood is offline  
Old 02-11-2004, 07:24 AM   #4 (permalink)
Dreams In Digital
 
SiNai's Avatar
 
Location: Iowa
Thread.sleep() definitely pauses the algorithm for that specified number of milliseconds, we've used it in class for some of the graphical things so they don't zoom right by.. Funny they put that into a sort- especially Microsystems, I hope somebody comes up with an answer to why this is so!
__________________
I can't seem to remember now
What it was like- to live life, before you.. symbiont
SiNai is offline  
Old 02-11-2004, 06:42 PM   #5 (permalink)
Psycho
 
hilbert25's Avatar
 
Location: nOvA
Merge sort can be parallelized with multiple threads. I haven't looked at the code, so I don't know if they are even doing that. It could be if they did set it up for multithreading and put the sleep in there so they didn't have to use synchronization? A really bad way of doing it that shouldn't work even.
hilbert25 is offline  
Old 02-11-2004, 06:43 PM   #6 (permalink)
Psycho
 
hilbert25's Avatar
 
Location: nOvA
Is it just as accurate without the sleeps? Also, how big a space are you sorting? And what kind of computer is this?
hilbert25 is offline  
Old 02-11-2004, 08:03 PM   #7 (permalink)
kel
WARNING: FLAMMABLE
 
Location: Ask Acetylene
There is no benefit in parallelizing merge sort on a single processor...
Parallelizing merge sort can't be done properly with threads because of the vagaries of the scheduler.

You need some sort of pram model guarantees.
__________________
"It better be funny"
kel is offline  
Old 02-11-2004, 08:42 PM   #8 (permalink)
Free Mars!
 
feelgood's Avatar
 
Location: I dunno, there's white people around me saying "eh" all the time
Quote:
Originally posted by hilbert25
Is it just as accurate without the sleeps? Also, how big a space are you sorting? And what kind of computer is this?
Still accurate without the sleep, the size of the data ranges from 8000 objects to 2 million. Although, I usually get a stack or out of memory errors with 2 million.
__________________
Looking out the window, that's an act of war. Staring at my shoes, that's an act of war. Committing an act of war? Oh you better believe that's an act of war
feelgood is offline  
 

Tags
java, merge, sort


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 02:10 PM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360