Ruby + Go + AWS + Postgres
Architecture cert — "which services solve this problem." No code, multiple choice.
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <title>All Out Of</title> | |
| <style> | |
| /* ---------- Page setup ---------- */ | |
| html, body { | |
| margin: 0; |
| relationships = Relationship.where(relationship: 'genealogy', resource_type: 'VmOrTemplate').select(:id, :resource_id, :ancestry).to_a | |
| rel_by_rel_id = relationships.index_by(:id) # relationship => resource_id | |
| rel_by_vm_id = relationships.index_by(:resource_id) # resource_id => ancestry | |
| Vm.where(:id => Relationship.select(:resource_id)).each_in_batches do |vm| | |
| ancestry = rel_by_vm_id[vm.id].ancestry.split("/").map { |rel_id| rel_by_rel_id[rel_id].resource_id.to_s }.join("/") | |
| vm.update_attribute(:ancestry => ancestry) | |
| end |
| curl -X POST http://admin:smartvm@localhost:3000/api/service_catalogs/#{id}/service_templates/1 -d '{"action" : "order"}' |
The [original] is modified in the following ways:
{} not [] for json syntax reasonsHere are a few ideas. I tried to keep them as independent as possible:
| #!/usr/bin/env ruby | |
| require "benchmark/ips" | |
| require "date" | |
| BEGIN_OF_JULY = Date.new(2015, 7, 1) | |
| END_OF_JULY = Date.new(2015, 7, 31) | |
| DAY_IN_JULY = Date.new(2015, 7, 15) | |
| RANGE = BEGIN_OF_JULY..END_OF_JULY |
| method | nil | speed | str | speed |
|---|---|---|---|---|
?split:[] |
9,761,148.9 i/s | 2,869,972.9 i/s | 3.40x | |
&.split||[] |
9,271,343.0 i/s | same | 2,879,248.1 i/s | 3.39x |
&&split||[] |
9,096,687.7 i/s | same | 2,941,303.8 i/s | 3.32x |
to_s.split |
4,288,858.0 i/s | 2.28x | 2,822,293.7 i/s | 3.46x |
ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]
| nil | slower | empty | slower | full | slower | |
|---|---|---|---|---|---|---|
x&.empty? |
11985357.7 i/s | same | 11617138.6 i/s | same | 11247144.5 i/s | same |
x.blank? |
9909235.8 i/s | 1.21x | 10488507.9 i/s | 1.14x | 10418916.8 i/s | 1.15x |
x.nil? || x.empty? |
10194622.1 i/s | 1.18x | 9584369.0 i/s | 1.25x | 9667811.7 i/s | 1.24x |
x.try!(:empty?) |
5437472.5 i/s | 2.20x | 3493090.9 i/s | 3.43x | 3523153.2 i/s | 3.40x |
note: in the tests, we are setting a different variable @x than the guard clause @x2.
I tested a terciary ?: vs the guard clause return if defined?() and they were about the same for pass and fail case
| test | int i/s | slower | text i/s | slower |
|---|---|---|---|---|
| eq2 | 6,315,053.7 i/s | same | 6,323,409.7 i/s | base |
| neq2 | 6,281,137.2 i/s | same | 3,707,761.0 i/s | 1.71x |
| eq | 5,978,924.2 i/s | same | 4,572,438.8 i/s | 1.38x |
| include | 4,368,299.8 i/s | 1.45x | 4,349,531.4 i/s | 1.45x |
| neq | 4,194,756.5 i/s | 1.51x | 4,170,358.7 i/s | 1.52x |