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 version of partition uses as media-of-three pivot | |
// instead of a randomized pivot. | |
func partition(data Interface, l, r int) int { | |
m := l + (r-l)/2 // Avoid integer overflow | |
medianOfThree(data, l, m, r) // Pivot is placed at l | |
i := l + 1 | |
for j := l + 1; j <= r; j++ { | |
if data.Less(j, l) { | |
if i != j { |
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 version of QuickSort reverts to InsertionSort | |
// when the slice size is below a cutoff value of 12. | |
// Add ShellSort before InsertionSort to help InsertionSort. | |
func QuickSort(data Interface, l int, r int, enableShellSort bool) { | |
if l >= r { | |
return | |
} | |
if r-l > 12 { | |
pivot := partition(data, l, r) |
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 version of QuickSort reverts to InsertionSort when the | |
// slice size is below a certain cutoff value. The cutoff value | |
// is parametrizable. | |
func QuickSort(data Interface, l int, r int, cutoff int) { | |
if l >= r { | |
return | |
} | |
if r-l > cutoff { | |
pivot := partition(data, l, r) |
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
package qsort | |
import "math/rand" | |
func QuickSort(data Interface, l int, r int) { | |
if l >= r { | |
return | |
} | |
pivot := partition(data, l, r) |
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
# It's a good idea to disable refresh when indexing documents to improve performance | |
client.indices.put_settings index: 'PatientA', body: { refresh_interval: -1 } | |
client.indices.put_settings index: 'PatientB', body: { refresh_interval: -1 } | |
# Now index (store) the documents | |
patient_a_doc1 = { | |
patient_name: 'PatientA', | |
content: 'The quick brown fox' | |
} | |
patient_a_doc2 = { |
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
req_body_for_patient_a = { | |
routing: 'PatientA', | |
filter: { | |
term: { patient_name: 'PatientA' } | |
} | |
} | |
req_body_for_patient_b = { | |
routing: 'PatientB', | |
filter: { |
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
def raw_put(path, body) | |
conn = Faraday.new url: 'http://localhost:9200' | |
conn.put(path) do |req| | |
req.body = body.to_json | |
req.headers['Content-Type'] = 'application/json' | |
end | |
end | |
# Create primary index | |
req_body = { |
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
require 'json' | |
require 'elasticsearch' | |
client = Elasticsearch::Client.new hosts: 'http://localhost:9200' | |
# Test that Elasticsearch is up | |
client.info |
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
require 'faraday' | |
require 'benchmark' | |
@conn = Faraday.new(url: 'https://www.google.com') | |
@threads = [] | |
Benchmark.bm(14) do |x| | |
x.report('no-threads') do | |
8.times { @conn.get } | |
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
require 'benchmark' | |
@threads = [] | |
Benchmark.bm(14) do |x| | |
x.report('no-threads') do | |
8.times do | |
tmp_array = [] | |
10_000_000.times { |n| tmp_array << n } | |
end | |
end |
NewerOlder