How to run examples:
- Run $ createdb nplusonedb to create DB
- Run specs $ rspec demo.rb
How to run examples:
func main() { | |
s := time.Now() | |
args := os.Args[1:] | |
if len(args) != 6 { // for format LogExtractor.exe -f "From Time" -t "To Time" -i "Log file directory location" | |
fmt.Println("Please give proper command line arguments") | |
return | |
} | |
startTimeArg := args[1] | |
finishTimeArg := args[3] |
echo -e "\e[1;40m" ; clear ; while :; do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $(( $RANDOM % 72 )) ;sleep 0.05; done|awk '{ letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()"; c=$4; letter=substr(letters,c,1);a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}' | |
# Binary version | |
echo -e "\e[1;40m" ; clear ; while :; do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $(( $RANDOM % 72 )) ;sleep 0.05; done|awk '{ letters="00100001100100011101011111101110110010110110011000011000011110010101000"; c=$4; letter=substr(letters,c,1);a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}' |
Picking the right architecture = Picking the right battles + Managing trade-offs
gem install fasterer
fasterer
Performance
in .rubocop.yml
as well.# taken from https://mrbrdo.wordpress.com/2013/09/25/manually-preloading-associations-in-rails-using-custom-scopessql/ | |
# collection association e.g. has_many | |
owners = People.all | |
association_name = :photos | |
owners.each do |owner| | |
records = Array(whatever_you_want) | |
MEASURING MEMORY USAGE
There are several gems that help with determining where a program allocates memory. The two that I most often use are allocation_tracer and memory_profiler.
Both tools can measure a whole program or they can be turned on and off to only measure certain parts of a program. Either method allows you to determine hotspots in your program and then act on the information. For example, while developing kramdown several years ago I found that the HTML converter class allocated huge amounts of throw-away strings. By changing this hotspot to a better alternative kramdown got faster and used less memory.
To get you started on using these two gems, here are two files that are intended to get pre-loaded using the -r switch of the ruby binary (i.e. ruby -I. -ralloc_tracer myscript.rb).
Credit: https://gettalong.org/blog/2017/memory-conscious-programming-in-ruby.html
rvm --create ree@benchmarks |
require 'bundler/setup' | |
require 'active_record' | |
include ActiveRecord::Tasks | |
db_dir = File.expand_path('../db', __FILE__) | |
config_dir = File.expand_path('../config', __FILE__) | |
DatabaseTasks.env = ENV['ENV'] || 'development' |