-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe0f0cf
commit a120bfe
Showing
4 changed files
with
37 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,229 +1,36 @@ | ||
def quicksort(arr, first, last) | ||
if first < last | ||
p_index = partition(arr, first, last) | ||
quicksort(arr, first, p_index - 1) | ||
quicksort(arr, p_index + 1, last) | ||
def quicksort(arr, first, last) | ||
if first < last | ||
p_index = partition(arr, first, last) | ||
quicksort(arr, first, p_index - 1) | ||
quicksort(arr, p_index + 1, last) | ||
end | ||
arr | ||
end | ||
arr | ||
end | ||
|
||
def partition(arr, first, last) | ||
# first select one element from the list, can be any element. | ||
# rearrange the list so all elements less than pivot are left of it, elements greater than pivot are right of it. | ||
pivot = arr[last] | ||
p_index = first | ||
|
||
i = first | ||
while i < last | ||
if arr[i] <= pivot | ||
arr[i], arr[p_index] = arr[p_index], arr[i] | ||
p_index += 1 | ||
|
||
def partition(arr, first, last) | ||
# first select one element from the list, can be any element. | ||
# rearrange the list so all elements less than pivot are left of it, elements greater than pivot are right of it. | ||
pivot = arr[last] | ||
p_index = first | ||
|
||
i = first | ||
while i < last | ||
if arr[i] <= pivot | ||
arr[i], arr[p_index] = arr[p_index], arr[i] | ||
p_index += 1 | ||
end | ||
i += 1 | ||
end | ||
i += 1 | ||
arr[p_index], arr[last] = pivot, arr[p_index] | ||
return p_index | ||
end | ||
arr[p_index], arr[last] = pivot, arr[p_index] | ||
return p_index | ||
end | ||
|
||
ary = [-3148, | ||
40741, | ||
-289, | ||
31694, | ||
-22828, | ||
-9882, | ||
39869, | ||
12322, | ||
2919, | ||
-546, | ||
-36740, | ||
-37935, | ||
-1189, | ||
45283, | ||
-37683, | ||
-22897, | ||
-14059, | ||
-20706, | ||
17990, | ||
1651, | ||
-27687, | ||
-28291, | ||
35797, | ||
11665, | ||
30133, | ||
20815, | ||
-17650, | ||
-17049, | ||
-28364, | ||
26684, | ||
-5775, | ||
17385, | ||
-814, | ||
-5730, | ||
32794, | ||
12898, | ||
-24589, | ||
-36925, | ||
29870, | ||
17952, | ||
11560, | ||
-28709, | ||
9033, | ||
21354, | ||
-45016, | ||
13108, | ||
-41449, | ||
-7710, | ||
5012, | ||
-7102, | ||
44794, | ||
7713, | ||
17860, | ||
22470, | ||
-1561, | ||
34306, | ||
-15949, | ||
-30591, | ||
-32625, | ||
-18440, | ||
40049, | ||
-17741, | ||
12960, | ||
-9316, | ||
7888, | ||
-46665, | ||
48564, | ||
43157, | ||
-11015, | ||
-32433, | ||
-32120, | ||
-21726, | ||
15983, | ||
-14303, | ||
26523, | ||
49528, | ||
-3069, | ||
-24148, | ||
9933, | ||
5645, | ||
-14865, | ||
-24112, | ||
16283, | ||
26173, | ||
-49288, | ||
-38175, | ||
37082, | ||
-5735, | ||
35491, | ||
-22697, | ||
-36692, | ||
-12300, | ||
-32687, | ||
-1480, | ||
-7078, | ||
-49971, | ||
-11778, | ||
1014, | ||
-14421, | ||
-27486, | ||
35756, | ||
31425, | ||
-18756, | ||
17784, | ||
-12397, | ||
-12571, | ||
-42049, | ||
-28397, | ||
-49199, | ||
3295, | ||
5866, | ||
-1519, | ||
-35589, | ||
-24147, | ||
-36093, | ||
47118, | ||
11375, | ||
-49103, | ||
12905, | ||
33154, | ||
-20682, | ||
41589, | ||
9874, | ||
-45801, | ||
23797, | ||
6279, | ||
46429, | ||
-1351, | ||
-24723, | ||
18072, | ||
37212, | ||
-4497, | ||
-27753, | ||
-4078, | ||
26706, | ||
-24936, | ||
19058, | ||
6548, | ||
35688, | ||
-13856, | ||
-6436, | ||
5306, | ||
-37817, | ||
32394, | ||
-35846, | ||
44917, | ||
44416, | ||
-37162, | ||
12724, | ||
46259, | ||
-49280, | ||
22538, | ||
37325, | ||
39482, | ||
-20706, | ||
5364, | ||
4748, | ||
-1563, | ||
-3005, | ||
3627, | ||
38549, | ||
-8617, | ||
-28161, | ||
3649, | ||
16355, | ||
14903, | ||
8031, | ||
25824, | ||
26657, | ||
-10556, | ||
-40646, | ||
-27760, | ||
-11060, | ||
32351, | ||
2241, | ||
-33702, | ||
33028, | ||
-47297, | ||
-43064, | ||
-23052, | ||
-16098, | ||
18916, | ||
1037, | ||
-46382, | ||
-35498, | ||
41437, | ||
29388, | ||
31576, | ||
-19602, | ||
22808, | ||
26564, | ||
-23372, | ||
44241, | ||
-11542, | ||
19241, | ||
-31165, | ||
-34920, | ||
40979, | ||
-14250, | ||
39684] | ||
|
||
puts quicksort(ary, 0, 199).inspect | ||
ary = [4050, 3681, 3270, 2408, 7332, 9499, 8967, 1085, 3803, 1503, 2787, 9549, 6272, 8059, 8124, 3439, 6958, 1038, 8123, 2024, 2009, 3816, 3134, 5386, 3618, 728, 2347, 9718, 4848, 3223, 6795, 1225, 7034, 3304, 9188, 1622, 3738, 3286, 1387, 8380, 3824, 7796, 979, 7624, 6045, 3395, 6249, 3310, 4021, 959, 5089, 681, 4123, 6406, 2947, 3003, 8527, 8992, 8969, 6082, 622, 4732, 1568, 4441, 3847, 1447, 1065, 3025, 4647, 3140, 1930, 9802, 2024, 4129, 4559, 2210, 3720, 7157, 6419, 1236, 7918, 7519, 4861, 6086, 9400, 9344, 7894, 1301, 7544, 225, 5837, 5356, 4399, 1335, 4517, 6590, 9702, 3403, 3127, 1361, 6815, 2160, 1389, 7136, 7430, 9354, 6478, 4882, 5726, 6029, 1295, 3474, 6431, 7854, 8756, 1006, 6971, 6831, 281, 8965, 6173, 8311, 5308, 4829, 5208, 9900, 4548, 7131, 8292, 3648, 5975, 7794, 7014, 3434, 4300, 2654, 60, 4126, 633, 5973, 8558, 9978, 2404, 2648, 3986, 2336, 7132, 9459, 6581, 4348, 8279, 5474, 7305, 2543, 2071, 219, 6497, 8454, 8552, 7291, 2019, 605, 5415, 6293, 1841, 1856, 1409, 7256, 381, 431, 6298, 5094, 8075, 5676, 5327, 4587, 832, 2711, 9755, 8823, 3065, 7792, 4229, 7884, 1255, 7464, 695, 5116, 2189, 5219, 2536, 9911, 9999, 9005, 4408, 4150, 5638, 3606, 8250, 9581, 1138, 2013, 2118, 257, 2461, 9484, 3324, 9801, 5927, 1175, 7468, 4462, 5461, 6026, 8159, 3652, 647, 6289, 9609, 597, 4279, 41, 3085, 9625, 9860, 3786, 9957, 4703, 9438, 1207, 4099, 2940, 4927, 546, 3856, 9970, 7685, 459, 9809, 5162, 2378, 1696, 3579, 4294, 368, 2208, 4328, 6584, 2756, 6965, 4982, 3855, 7191, 7042, 6195, 9705, 8751, 6463, 6294, 7203, 5231, 8397, 5306, 6219, 8783, 8249, 2763, 2754, 2430, 9387, 4377, 5777, 4249, 9753, 3626, 465, 4426, 3146, 2494, 4783, 7827, 7404, 9560, 4708, 8894, 9960, 9747, 5776, 2000, 833, 1326, 1640, 2686, 959, 3825, 141, 7041, 7471, 4605, 1712, 9618, 6436, 1382, 7537, 6299, 8551, 3992, 1685, 9280, 3347, 928, 9594, 5940, 6982, 3777, 1366, 4189, 8696, 6981, 8604, 3727, 3319, 5589, 7877, 7569, 3549, 1883, 3593, 7479, 1528, 472, 63, 6297, 8592, 3143, 3852, 3851, 7273, 7358, 8239, 6438, 6148, 4472, 7806, 3619, 3772, 6864, 6219, 556, 2924, 6452, 8955, 5861, 8750, 9972, 6398, 4348, 4342, 1650, 5347, 243, 9716, 5373, 6897, 1518, 9215, 6, 3213, 1231, 6519, 4934, 2048, 3277, 5672, 9069, 175, 4071, 4455, 7212, 3951, 8314, 7303, 9196, 1330, 5491, 2388, 8535, 8554, 2862, 8678, 4713, 5943, 9700, 5365, 5981, 7416, 6584, 1831, 5028, 355, 6720, 311, 7419, 8036, 6629, 8899, 8320, 7789, 4142, 5506, 9931, 3716, 1785, 6264, 3807, 5795, 2097, 9082, 5433, 4643, 4602, 376, 9406, 3591, 5858, 1442, 2760, 1384, 6854, 7840, 5525, 2007, 2895, 4750, 4561, 3997, 1243, 6347, 2546, 6851, 5145, 410, 3766, 864, 5019, 1914, 6945, 3217, 1303, 5717, 9916, 5763, 414, 2269, 8694, 2239, 8138, 1567, 241, 812, 3761, 3867, 7237, 1310, 3827, 1591, 7628, 7076, 6825, 1069, 7354, 5718, 273, 8671, 8956, 4741, 3659, 1081, 7758, 179, 9425, 484, 1608, 2261, 4949, 8973, 5627, 8050, 470, 1427, 3981, 1338, 5538, 6100, 1626, 7110, 7836, 7794, 845, 3502, 4040, 6581, 885, 1691, 3080, 3351, 5802, 3495, 263, 4825, 3571, 7353, 7776, 4916, 9040, 811, 9810, 4749, 8591, 4742, 1729, 8153, 1188, 6104, 6267, 9107, 5193, 9817, 1038, 4734, 3874, 5734, 9889, 2852, 1839, 3082, 4941, 3263, 5016, 5611, 7811, 6231, 3040, 9503, 977, 869, 335, 8305, 7808, 1007, 2096, 6776, 4352, 7771, 533, 2704, 8384, 426, 3442, 9920, 4046, 7997, 5310, 4390, 1366, 9777, 6789, 4843, 6111, 6913, 3309, 9944, 5416, 6389, 2288, 5495, 8594, 6872, 6283, 9200, 9221, 7399, 7369, 1726, 3283, 7290, 783, 5123, 5367, 4178, 4041, 8645, 4074, 6573, 1702, 6765, 4207, 1321, 5710, 9021, 1111, 786, 4273, 6182, 114, 7489, 4821, 8527, 9313, 9917, 3335, 6834, 46, 848, 3856, 1569, 2272, 6504, 7095, 2934, 5377, 8148, 4068, 8286, 9515, 1871, 1565, 2071, 6867, 2317, 6798, 5523, 7550, 4596, 2770, 5389, 4581, 2595, 4572, 3830, 7969, 8937, 6521, 6096, 4373, 7341, 5272, 154, 8366, 567, 9295, 4253, 6140, 9317, 1146, 5809, 7220, 477, 7773, 2043, 3279, 1428, 8225, 7096, 9747, 7480, 4328, 5339, 8687, 9949, 7208, 4579, 1684, 6248, 7285, 5093, 6975, 8449, 8946, 620, 83, 361, 853, 809, 5990, 9021, 3145, 7799, 8166, 5490, 8570, 2532, 2139, 7894, 4714, 3199, 7478, 8535, 1374, 6372, 8132, 5496, 4272, 6463, 7895, 6024, 7685, 6903, 9115, 9159, 3691, 2042, 5826, 9000, 6071, 9723, 3373, 2071, 3829, 3181, 5916, 6236, 6521, 2093, 5014, 8812, 9128, 7051, 9757, 7501, 7014, 5089, 2184, 7591, 3148, 368, 7690, 4141, 9217, 3437, 5391, 2974, 6382, 851, 1245, 3550, 9253, 318, 6088, 9602, 965, 1059, 3077, 1617, 2528, 2726, 7861, 9761, 9381, 6516, 5340, 8383, 6554, 1869, 6964, 2278, 5452, 8308, 5638, 7525, 3568, 3429, 4155, 216, 8473, 2782, 2622, 7613, 9710, 6429, 7164, 3826, 9247, 9429, 3196, 8564, 2446, 1024, 9538, 9743, 3418, 2631, 5903, 8423, 3205, 9124, 9264, 7838, 4472, 7948, 1053, 2040, 9365, 7265, 5729, 9498, 7968, 1730, 7431, 5917, 7153, 2928, 4725, 9785, 9597, 7801, 2792, 2305, 5371, 5968, 6760, 904, 5278, 7872, 8899, 3875, 4884, 3851, 6204, 5295, 4470, 5843, 6304, 6330, 7594, 7585, 4773, 9322, 4676, 9751, 7462, 8795, 7867, 6735, 1452, 9727, 2783, 2773, 1507, 3126, 3290, 2830, 6931, 899, 2874, 4673, 7020, 8338, 5768, 3872, 2497, 5561, 4006, 6898, 6342, 1769, 6677, 6053, 9534, 1099, 4707, 9826, 3239, 2050, 85, 8671, 4899, 135, 6883, 7155, 5469, 737, 4925, 5076, 7021, 7630, 6797, 3044, 8119, 7160, 6433, 8993, 1360, 8889, 5298, 5053, 8371, 8923, 1985, 9946, 4377, 7008, 787, 3409, 408, 5665, 1911, 3973, 1577, 7502, 3170, 4629, 6033, 4201, 8013, 7126, 3469, 6186, 1727, 1350, 8472, 6144, 6955, 3400, 9399, 5866, 8181, 9552, 2427, 8941, 4367, 4097, 3101, 4851, 8329, 6119, 2560, 6776, 3168, 451, 2215, 4881, 8950, 4852, 4921, 6845, 7851, 3651, 5014, 5210, 9164, 7144, 5252, 8745, 2501, 3523, 922, 9532, 6177, 4491, 9434, 930, 4310, 6961, 4065, 1888, 94, 2307, 1170, 4409, 610, 5757, 6044, 1583, 8536, 2775, 1726, 3514, 1442, 2412, 9980, 4240, 5702, 6135, 100, 2064, 443, 6235, 3767, 506, 5289, 6472, 8959, 1562, 2322, 6787, 2936, 6902, 5937, 6032, 2521] | ||
a = ary | ||
puts quicksort(a, 0, a.size - 1).inspect | ||
|
||
100.times do | ||
a = ary | ||
quicksort(a, 0, ary.size - 1) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,4 @@ benchmark: | |
0, | ||
999 | ||
) | ||
loop_count: 500 | ||
loop_count: 2000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
cargo install --features perf --path monoruby | ||
perf record -F 200 -g -- monoruby $@ | ||
RUSTFLAGS=-Cforce-frame-pointers cargo install --features perf --path monoruby | ||
perf record -F 2000 -g -- monoruby $@ | ||
perf script | ../FlameGraph/stackcollapse-perf.pl | ../FlameGraph/flamegraph.pl > out.svg | ||
rm perf.data* | ||
|