my dog learned polymorphism*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes (Regex + CharSequence) VS (Regex + StringBuffer) VS (startsWith + StringBuffer) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "(Regex + CharSequence) VS (Regex + StringBuffer) VS (startsWith + StringBuffer)" Watch "(Regex + CharSequence) VS (Regex + StringBuffer) VS (startsWith + StringBuffer)" New topic
Author

(Regex + CharSequence) VS (Regex + StringBuffer) VS (startsWith + StringBuffer)

Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
I'm sure the results will be of no surprise to you guys but I thought I'd share this.
Everything besides the search mechanism is the same for all tests, all threads get back a Map containing Room objects and just output the number they got back, as well as the duration spent searching.
The thread names will be a little weird because JUnit doesn't require the test to be re-started, and I've run a few in between.
anyway
TESTED WITH 100 THREADS USING PATTERN COMPILE BUT CHECKING EACH COLUMN VALUE ONE AT A TIME AFTER READING A SINGLE RECORD INTO A STRINGBUFFER
room map size : 27
Thread : Thread-269 spent 1515 milliseconds searching.
room map size : 27
Thread : Thread-272 spent 1531 milliseconds searching.
room map size : 27
Thread : Thread-285 spent 1531 milliseconds searching.
room map size : 27
Thread : Thread-276 spent 1531 milliseconds searching.
room map size : 27
Thread : Thread-275 spent 1531 milliseconds searching.
room map size : 27
Thread : Thread-277 spent 1546 milliseconds searching.
room map size : 27
Thread : Thread-279 spent 1546 milliseconds searching.
room map size : 27
Thread : Thread-273 spent 1546 milliseconds searching.
room map size : 27
Thread : Thread-289 spent 1546 milliseconds searching.
room map size : 27
Thread : Thread-265 spent 1578 milliseconds searching.
room map size : 27
Thread : Thread-283 spent 1562 milliseconds searching.
room map size : 27
Thread : Thread-294 spent 1562 milliseconds searching.
room map size : 27
Thread : Thread-286 spent 1578 milliseconds searching.
room map size : 27
Thread : Thread-292 spent 1578 milliseconds searching.
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
Thread : Thread-266 spent 1641 milliseconds searching.
Thread : Thread-281 spent 1625 milliseconds searching.
Thread : Thread-263 spent 1641 milliseconds searching.
Thread : Thread-307 spent 1625 milliseconds searching.
Thread : Thread-274 spent 1625 milliseconds searching.
Thread : Thread-267 spent 1656 milliseconds searching.
Thread : Thread-259 spent 1656 milliseconds searching.
Thread : Thread-261 spent 1656 milliseconds searching.
Thread : Thread-270 spent 1640 milliseconds searching.
Thread : Thread-282 spent 1640 milliseconds searching.
Thread : Thread-326 spent 1625 milliseconds searching.
Thread : Thread-306 spent 1640 milliseconds searching.
Thread : Thread-317 spent 1625 milliseconds searching.
Thread : Thread-260 spent 1656 milliseconds searching.
Thread : Thread-316 spent 1625 milliseconds searching.
Thread : Thread-268 spent 1656 milliseconds searching.
Thread : Thread-296 spent 1640 milliseconds searching.
Thread : Thread-256 spent 1672 milliseconds searching.
Thread : Thread-254 spent 1688 milliseconds searching.
room map size : 27
Thread : Thread-323 spent 1844 milliseconds searching.
room map size : 27
Thread : Thread-288 spent 1875 milliseconds searching.
room map size : 27
Thread : Thread-278 spent 1984 milliseconds searching.
room map size : 27
Thread : Thread-310 spent 2094 milliseconds searching.
room map size : 27
Thread : Thread-258 spent 2312 milliseconds searching.
room map size : 27
Thread : Thread-325 spent 2313 milliseconds searching.
room map size : 27
Thread : Thread-314 spent 2313 milliseconds searching.
room map size : 27
Thread : Thread-290 spent 2328 milliseconds searching.
room map size : 27
Thread : Thread-295 spent 2343 milliseconds searching.
room map size : 27
Thread : Thread-322 spent 2328 milliseconds searching.
room map size : 27
Thread : Thread-345 spent 2328 milliseconds searching.
room map size : 27
Thread : Thread-351 spent 2344 milliseconds searching.
room map size : 27
Thread : Thread-352 spent 2344 milliseconds searching.
room map size : 27
Thread : Thread-324 spent 2344 milliseconds searching.
room map size : 27
Thread : Thread-335 spent 2359 milliseconds searching.
room map size : 27
Thread : Thread-280 spent 2374 milliseconds searching.
room map size : 27
Thread : Thread-344 spent 2375 milliseconds searching.
room map size : 27
Thread : Thread-336 spent 2375 milliseconds searching.
room map size : 27
Thread : Thread-301 spent 2390 milliseconds searching.
room map size : 27
Thread : Thread-311 spent 2391 milliseconds searching.
room map size : 27
Thread : Thread-337 spent 2391 milliseconds searching.
room map size : 27
Thread : Thread-348 spent 2391 milliseconds searching.
room map size : 27
Thread : Thread-287 spent 2406 milliseconds searching.
room map size : 27
Thread : Thread-334 spent 2406 milliseconds searching.
room map size : 27
Thread : Thread-298 spent 2421 milliseconds searching.
room map size : 27
Thread : Thread-341 spent 2406 milliseconds searching.
room map size : 27
Thread : Thread-328 spent 2406 milliseconds searching.
room map size : 27
Thread : Thread-333 spent 2422 milliseconds searching.
room map size : 27
Thread : Thread-313 spent 2422 milliseconds searching.
room map size : 27
Thread : Thread-318 spent 2438 milliseconds searching.
room map size : 27
Thread : Thread-308 spent 2453 milliseconds searching.
room map size : 27
Thread : Thread-293 spent 2453 milliseconds searching.
room map size : 27
Thread : Thread-255 spent 2485 milliseconds searching.
room map size : 27
Thread : Thread-342 spent 2453 milliseconds searching.
room map size : 27
Thread : Thread-321 spent 2453 milliseconds searching.
room map size : 27
Thread : Thread-340 spent 2453 milliseconds searching.
room map size : 27
Thread : Thread-343 spent 2469 milliseconds searching.
room map size : 27
Thread : Thread-257 spent 2516 milliseconds searching.
room map size : 27
Thread : Thread-305 spent 2484 milliseconds searching.
room map size : 27
Thread : Thread-302 spent 2499 milliseconds searching.
room map size : 27
Thread : Thread-346 spent 2500 milliseconds searching.
room map size : 27
Thread : Thread-309 spent 2500 milliseconds searching.
room map size : 27
Thread : Thread-315 spent 2500 milliseconds searching.
room map size : 27
Thread : Thread-299 spent 2531 milliseconds searching.
room map size : 27
Thread : Thread-291 spent 2531 milliseconds searching.
room map size : 27
Thread : Thread-329 spent 2516 milliseconds searching.
room map size : 27
Thread : Thread-349 spent 2516 milliseconds searching.
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
Thread : Thread-350 spent 2563 milliseconds searching.
room map size : 27
Thread : Thread-327 spent 2563 milliseconds searching.
Thread : Thread-262 spent 2594 milliseconds searching.
Thread : Thread-338 spent 2563 milliseconds searching.
Thread : Thread-253 spent 2610 milliseconds searching.
Thread : Thread-300 spent 2578 milliseconds searching.
Thread : Thread-331 spent 2563 milliseconds searching.
Thread : Thread-284 spent 2578 milliseconds searching.
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
room map size : 27
Thread : Thread-304 spent 2624 milliseconds searching.
Thread : Thread-312 spent 2609 milliseconds searching.
Thread : Thread-339 spent 2609 milliseconds searching.
Thread : Thread-330 spent 2609 milliseconds searching.
Thread : Thread-347 spent 2609 milliseconds searching.
Thread : Thread-271 spent 2640 milliseconds searching.
Thread : Thread-319 spent 2625 milliseconds searching.
Thread : Thread-332 spent 2625 milliseconds searching.
Thread : Thread-320 spent 2625 milliseconds searching.
Thread : Thread-303 spent 2640 milliseconds searching.
Thread : Thread-264 spent 2656 milliseconds searching.
Thread : Thread-297 spent 2640 milliseconds searching.

===============================================================================

TESTED WITH 100 THREADS USING startsWith AND STILL CHECKING EACH COLUMN VALUE ONE AT A TIME AFTER READING A SINGLE RECORD INTO A STRINGBUFFER
room map size : 27
Thread : Thread-126 spent 2453 milliseconds searching.
room map size : 27
Thread : Thread-122 spent 2468 milliseconds searching.
room map size : 27
Thread : Thread-124 spent 2718 milliseconds searching.
room map size : 27
Thread : Thread-119 spent 2828 milliseconds searching.
room map size : 27
Thread : Thread-123 spent 2859 milliseconds searching.
room map size : 27
Thread : Thread-113 spent 2890 milliseconds searching.
room map size : 27
Thread : Thread-115 spent 2937 milliseconds searching.
room map size : 27
Thread : Thread-140 spent 3016 milliseconds searching.
room map size : 27
Thread : Thread-136 spent 3016 milliseconds searching.
room map size : 27
Thread : Thread-168 spent 2985 milliseconds searching.
room map size : 27
Thread : Thread-106 spent 3046 milliseconds searching.
room map size : 27
Thread : Thread-150 spent 3015 milliseconds searching.
room map size : 27
Thread : Thread-137 spent 3047 milliseconds searching.
room map size : 27
Thread : Thread-125 spent 3062 milliseconds searching.
room map size : 27
Thread : Thread-130 spent 3047 milliseconds searching.
room map size : 27
Thread : Thread-179 spent 3016 milliseconds searching.
room map size : 27
Thread : Thread-196 spent 3000 milliseconds searching.
room map size : 27
Thread : Thread-178 spent 3032 milliseconds searching.
room map size : 27
Thread : Thread-151 spent 3187 milliseconds searching.
room map size : 27
Thread : Thread-105 spent 3218 milliseconds searching.
room map size : 27
Thread : Thread-180 spent 3172 milliseconds searching.
room map size : 27
Thread : Thread-192 spent 3156 milliseconds searching.
room map size : 27
Thread : Thread-134 spent 3219 milliseconds searching.
room map size : 27
Thread : Thread-184 spent 3156 milliseconds searching.
room map size : 27
Thread : Thread-177 spent 3204 milliseconds searching.
room map size : 27
Thread : Thread-133 spent 3250 milliseconds searching.
room map size : 27
Thread : Thread-169 spent 3235 milliseconds searching.
room map size : 27
Thread : Thread-194 spent 3203 milliseconds searching.
room map size : 27
Thread : Thread-135 spent 3266 milliseconds searching.
room map size : 27
Thread : Thread-173 spent 3250 milliseconds searching.
room map size : 27
Thread : Thread-112 spent 3296 milliseconds searching.
room map size : 27
Thread : Thread-159 spent 3281 milliseconds searching.
room map size : 27
Thread : Thread-167 spent 3266 milliseconds searching.
room map size : 27
Thread : Thread-176 spent 3266 milliseconds searching.
room map size : 27
Thread : Thread-157 spent 3281 milliseconds searching.
room map size : 27
Thread : Thread-171 spent 3282 milliseconds searching.
room map size : 27
Thread : Thread-199 spent 3250 milliseconds searching.
room map size : 27
Thread : Thread-193 spent 3250 milliseconds searching.
room map size : 27
Thread : Thread-200 spent 3265 milliseconds searching.
room map size : 27
Thread : Thread-145 spent 3312 milliseconds searching.
room map size : 27
Thread : Thread-197 spent 3281 milliseconds searching.
room map size : 27
Thread : Thread-182 spent 3313 milliseconds searching.
room map size : 27
Thread : Thread-139 spent 3360 milliseconds searching.
room map size : 27
Thread : Thread-129 spent 3360 milliseconds searching.
room map size : 27
Thread : Thread-195 spent 3297 milliseconds searching.
room map size : 27
Thread : Thread-148 spent 3359 milliseconds searching.
room map size : 27
Thread : Thread-185 spent 3437 milliseconds searching.
room map size : 27
Thread : Thread-154 spent 3500 milliseconds searching.
room map size : 27
Thread : Thread-103 spent 3547 milliseconds searching.
room map size : 27
Thread : Thread-149 spent 3500 milliseconds searching.
room map size : 27
Thread : Thread-172 spent 3485 milliseconds searching.
room map size : 27
room map size : 27
room map size : 27
Thread : Thread-158 spent 3531 milliseconds searching.
Thread : Thread-189 spent 3484 milliseconds searching.
Thread : Thread-144 spent 3531 milliseconds searching.
room map size : 27
Thread : Thread-198 spent 3500 milliseconds searching.
room map size : 27
Thread : Thread-116 spent 3578 milliseconds searching.
room map size : 27
Thread : Thread-181 spent 3532 milliseconds searching.
room map size : 27
Thread : Thread-109 spent 3593 milliseconds searching.
room map size : 27
Thread : Thread-110 spent 3593 milliseconds searching.
room map size : 27
Thread : Thread-187 spent 3531 milliseconds searching.
room map size : 27
Thread : Thread-175 spent 3579 milliseconds searching.
room map size : 27
Thread : Thread-127 spent 3625 milliseconds searching.
room map size : 27
Thread : Thread-188 spent 3547 milliseconds searching.
room map size : 27
Thread : Thread-141 spent 3610 milliseconds searching.
room map size : 27
Thread : Thread-156 spent 3609 milliseconds searching.
room map size : 27
Thread : Thread-138 spent 3625 milliseconds searching.
room map size : 27
Thread : Thread-128 spent 3656 milliseconds searching.
room map size : 27
Thread : Thread-163 spent 3610 milliseconds searching.
room map size : 27
Thread : Thread-160 spent 3640 milliseconds searching.
room map size : 27
Thread : Thread-190 spent 3609 milliseconds searching.
room map size : 27
Thread : Thread-201 spent 3609 milliseconds searching.
room map size : 27
Thread : Thread-143 spent 3672 milliseconds searching.
room map size : 27
Thread : Thread-162 spent 3641 milliseconds searching.
room map size : 27
Thread : Thread-104 spent 3703 milliseconds searching.
room map size : 27
Thread : Thread-186 spent 3625 milliseconds searching.
room map size : 27
Thread : Thread-114 spent 3703 milliseconds searching.
room map size : 27
Thread : Thread-165 spent 3657 milliseconds searching.
room map size : 27
Thread : Thread-191 spent 3750 milliseconds searching.
room map size : 27
Thread : Thread-161 spent 3797 milliseconds searching.
room map size : 27
Thread : Thread-152 spent 3812 milliseconds searching.
room map size : 27
Thread : Thread-146 spent 3812 milliseconds searching.
room map size : 27
Thread : Thread-108 spent 3843 milliseconds searching.
room map size : 27
Thread : Thread-131 spent 3828 milliseconds searching.
room map size : 27
Thread : Thread-111 spent 3859 milliseconds searching.
room map size : 27
Thread : Thread-117 spent 3859 milliseconds searching.
room map size : 27
Thread : Thread-142 spent 3844 milliseconds searching.
room map size : 27
Thread : Thread-118 spent 3875 milliseconds searching.
room map size : 27
Thread : Thread-121 spent 3875 milliseconds searching.
room map size : 27
Thread : Thread-132 spent 3860 milliseconds searching.
room map size : 27
Thread : Thread-120 spent 3890 milliseconds searching.
room map size : 27
Thread : Thread-107 spent 3890 milliseconds searching.
room map size : 27
Thread : Thread-164 spent 3844 milliseconds searching.
room map size : 27
Thread : Thread-147 spent 3875 milliseconds searching.
room map size : 27
Thread : Thread-153 spent 3875 milliseconds searching.
room map size : 27
Thread : Thread-183 spent 3875 milliseconds searching.
room map size : 27
Thread : Thread-166 spent 3875 milliseconds searching.
room map size : 27
Thread : Thread-155 spent 3890 milliseconds searching.
room map size : 27
Thread : Thread-202 spent 3859 milliseconds searching.
room map size : 27
Thread : Thread-170 spent 3891 milliseconds searching.
room map size : 27
Thread : Thread-174 spent 3891 milliseconds searching.
=================================================================================
TESTED WITH 100 THREADS USING A CharSequence OF THE ENTIRE FILE
AND THEN RUNNING THE REGEX Pattern MATCHER THROUGH THE CharSequence

room map size : 27
Thread : Thread-1492 spent 125 milliseconds searching.
room map size : 27
Thread : Thread-1446 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1493 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1444 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1494 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1445 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1495 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1442 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1496 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1443 spent 46 milliseconds searching.
room map size : 27
Thread : Thread-1441 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1497 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1498 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1452 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1499 spent 46 milliseconds searching.
room map size : 27
Thread : Thread-1405 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1500 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1450 spent 63 milliseconds searching.
room map size : 27
Thread : Thread-1404 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1451 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1403 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1449 spent 46 milliseconds searching.
room map size : 27
Thread : Thread-1501 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1402 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1447 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1448 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1479 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1433 spent 47 milliseconds searching.
room map size : 27
Thread : Thread-1480 spent 78 milliseconds searching.
room map size : 27
Thread : Thread-1465 spent 109 milliseconds searching.
room map size : 27
Thread : Thread-1431 spent 156 milliseconds searching.
room map size : 27
Thread : Thread-1481 spent 203 milliseconds searching.
room map size : 27
Thread : Thread-1432 spent 250 milliseconds searching.
room map size : 27
Thread : Thread-1482 spent 297 milliseconds searching.
room map size : 27
Thread : Thread-1483 spent 328 milliseconds searching.
room map size : 27
Thread : Thread-1430 spent 375 milliseconds searching.
room map size : 27
Thread : Thread-1484 spent 422 milliseconds searching.
room map size : 27
Thread : Thread-1428 spent 469 milliseconds searching.
room map size : 27
Thread : Thread-1429 spent 516 milliseconds searching.
room map size : 27
Thread : Thread-1439 spent 562 milliseconds searching.
room map size : 27
Thread : Thread-1485 spent 609 milliseconds searching.
room map size : 27
Thread : Thread-1486 spent 656 milliseconds searching.
room map size : 27
Thread : Thread-1440 spent 703 milliseconds searching.
room map size : 27
Thread : Thread-1487 spent 750 milliseconds searching.
room map size : 27
Thread : Thread-1488 spent 797 milliseconds searching.
room map size : 27
Thread : Thread-1438 spent 844 milliseconds searching.
room map size : 27
Thread : Thread-1436 spent 891 milliseconds searching.
room map size : 27
Thread : Thread-1437 spent 937 milliseconds searching.
room map size : 27
Thread : Thread-1489 spent 1000 milliseconds searching.
room map size : 27
Thread : Thread-1434 spent 1031 milliseconds searching.
room map size : 27
Thread : Thread-1490 spent 1078 milliseconds searching.
room map size : 27
Thread : Thread-1435 spent 1141 milliseconds searching.
room map size : 27
Thread : Thread-1491 spent 1187 milliseconds searching.
room map size : 27
Thread : Thread-1466 spent 1234 milliseconds searching.
room map size : 27
Thread : Thread-1467 spent 1359 milliseconds searching.
room map size : 27
Thread : Thread-1421 spent 1406 milliseconds searching.
room map size : 27
Thread : Thread-1468 spent 1453 milliseconds searching.
room map size : 27
Thread : Thread-1469 spent 1500 milliseconds searching.
room map size : 27
Thread : Thread-1470 spent 1531 milliseconds searching.
room map size : 27
Thread : Thread-1419 spent 1578 milliseconds searching.
room map size : 27
Thread : Thread-1471 spent 1625 milliseconds searching.
room map size : 27
Thread : Thread-1472 spent 1671 milliseconds searching.
room map size : 27
Thread : Thread-1426 spent 1703 milliseconds searching.
room map size : 27
Thread : Thread-1427 spent 1750 milliseconds searching.
room map size : 27
Thread : Thread-1473 spent 1796 milliseconds searching.
room map size : 27
Thread : Thread-1474 spent 1843 milliseconds searching.
room map size : 27
Thread : Thread-1425 spent 1890 milliseconds searching.
room map size : 27
Thread : Thread-1475 spent 1937 milliseconds searching.
room map size : 27
Thread : Thread-1476 spent 1984 milliseconds searching.
room map size : 27
Thread : Thread-1423 spent 2031 milliseconds searching.
room map size : 27
Thread : Thread-1424 spent 2078 milliseconds searching.
room map size : 27
Thread : Thread-1477 spent 2109 milliseconds searching.
room map size : 27
Thread : Thread-1422 spent 2156 milliseconds searching.
room map size : 27
Thread : Thread-1478 spent 2203 milliseconds searching.
room map size : 27
Thread : Thread-1411 spent 2250 milliseconds searching.
room map size : 27
Thread : Thread-1453 spent 2296 milliseconds searching.
room map size : 27
Thread : Thread-1454 spent 2343 milliseconds searching.
room map size : 27
Thread : Thread-1412 spent 2390 milliseconds searching.
room map size : 27
Thread : Thread-1415 spent 2593 milliseconds searching.
room map size : 27
Thread : Thread-1410 spent 2796 milliseconds searching.
room map size : 27
Thread : Thread-1408 spent 2843 milliseconds searching.
room map size : 27
Thread : Thread-1456 spent 2859 milliseconds searching.
room map size : 27
Thread : Thread-1414 spent 2859 milliseconds searching.
room map size : 27
Thread : Thread-1464 spent 2875 milliseconds searching.
room map size : 27
Thread : Thread-1413 spent 2875 milliseconds searching.
room map size : 27
Thread : Thread-1455 spent 3093 milliseconds searching.
room map size : 27
Thread : Thread-1420 spent 3141 milliseconds searching.
room map size : 27
Thread : Thread-1409 spent 3171 milliseconds searching.
room map size : 27
Thread : Thread-1457 spent 3203 milliseconds searching.
room map size : 27
Thread : Thread-1406 spent 3250 milliseconds searching.
room map size : 27
Thread : Thread-1458 spent 3296 milliseconds searching.
room map size : 27
Thread : Thread-1407 spent 3328 milliseconds searching.
room map size : 27
Thread : Thread-1459 spent 3375 milliseconds searching.
room map size : 27
Thread : Thread-1460 spent 3421 milliseconds searching.
room map size : 27
Thread : Thread-1418 spent 3453 milliseconds searching.
room map size : 27
Thread : Thread-1461 spent 3500 milliseconds searching.
room map size : 27
Thread : Thread-1416 spent 3546 milliseconds searching.
room map size : 27
Thread : Thread-1462 spent 3593 milliseconds searching.
room map size : 27
Thread : Thread-1417 spent 3625 milliseconds searching.
room map size : 27
Thread : Thread-1463 spent 3671 milliseconds searching.
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
I forgot to metion thats a new CharSequence for every search, and as I said all other processing stayed the same for all tests, including validations.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Interesting - your results are surprising to me in several ways. For one, comparing the first two techniques: I would have expected startsWith() to be faster (or at least, no slower) than a compiled regex. Just because I'd expect Sun's startsWith() to be pretty well-optimized (it's a simple operation after all) while a compiled regex, being more complex and variable in nature, might not be optimized as well. I'm at a loss to guess why the regex might be significantly faster in this case.
The final result is surprising too, in two ways. First, that it's so much faster initially. I would have thought that it would be wasting a lot of time to search the entire file, considering that for a final result you're only interested in the matches that occur in a particular field. But I guess it's faster to keep the initial search as simple as possible, avoiding the extra object churn of creating a new String for each field before examining it. (Or possibly some other CharSequence). I assume that after you identify the records that seem to have a match (using the initial big CharSequence search) you then check the record more carefully to see if the regex match occurs in the appropriate field? This would of course be more time-intensive, but at least it's only done on the small subset of records which matches the initial regex search, right?
Come to think of it, aside from object churn there's the fact that the first two techniques probably have a lot of lock aquisition (and release and reaquisition) as you request a read of each individual record. The "one big search" strategy just requires a single big read - once you've got a copy of the whole file in a buffer, you can be completely independant of the other threads, right? That's a nice plus...
Anyway, the other odd thing about your final results is that while "one big read" is very very fast initially, it's performance seems to degrade sharply for the later threads. The average performance still seems better than the first two methods, but there's cause for concern I think - what happens if you use 200 or 300 threads rather than 100? I wonder what the cause of this slowdown is? One possibility is that "one big read" requires more memory at one time, and the later threads are forcing more memory to be allocated to the JVM? Perhaps you can try running with the -verbose:gc option while running these tests, to see what's going on with total memory usage at the same time.
I'm just now considering how to implement find() for my assignment. I wouldn't have expected OBR to be worthwhile, but based on your results maybe I'll give it a try. Since the instructions don't mention performance much, I'm thinking that there's little reason to worry about what happens if there are 100 simultaneous requests. But a single user may very well notice the difference between a 47 ms response and a 1.5-2.5 ms response, even if performance wasn't cited as a big concern. Thanks for the info - I'll let you know if I come up with additional data.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: (Regex + CharSequence) VS (Regex + StringBuffer) VS (startsWith + StringBuffer)
 
Similar Threads
Java nio
EJB Lookup problem
How many class' are there in JDK?
Javaranch Search Feature Gone?
EJB creation failed