From 8afdbfbdc092fb2663b6409a68b552e6f122cd4e Mon Sep 17 00:00:00 2001 From: rischev Date: Sun, 22 Oct 2023 05:32:39 +0300 Subject: [PATCH] rm large files --- .byebug_history | 64 ++ case-study-template.md | 71 ++- result.json | 1 + ruby-prof-callgrind.rb | 11 + ruby-prof-callstack.rb | 11 + ruby-prof-flat.rb | 10 + ruby_prof_reports/callgrind.out.1 | 274 +++++++++ ruby_prof_reports/callgrind.out.2 | 302 ++++++++++ ruby_prof_reports/callgrind.out.3 | 282 +++++++++ ruby_prof_reports/callgrind.out.4 | 298 ++++++++++ ruby_prof_reports/callgrind.out.5 | 166 ++++++ ruby_prof_reports/callgrind.out.6 | 290 ++++++++++ ruby_prof_reports/callgrind.out.7 | 326 +++++++++++ ruby_prof_reports/callstack1.html | 902 +++++++++++++++++++++++++++++ ruby_prof_reports/callstack2.html | 916 +++++++++++++++++++++++++++++ ruby_prof_reports/callstack3.html | 902 +++++++++++++++++++++++++++++ ruby_prof_reports/callstack4.html | 918 +++++++++++++++++++++++++++++ ruby_prof_reports/callstack6.html | 886 ++++++++++++++++++++++++++++ ruby_prof_reports/callstack7.html | 930 ++++++++++++++++++++++++++++++ ruby_prof_reports/flat1.txt | 55 ++ ruby_prof_reports/flat2.txt | 59 ++ ruby_prof_reports/flat3.txt | 55 ++ ruby_prof_reports/flat4.txt | 57 ++ ruby_prof_reports/flat5.txt | 46 ++ ruby_prof_reports/flat6.txt | 60 ++ ruby_prof_reports/flat7.txt | 62 ++ stackprof-speedscope.rb | 9 + stackprof.rb | 6 + stackprof_reports/stackprof.dump | Bin 0 -> 109 bytes stackprof_reports/stackprof.json | 1 + task-1.rb | 170 ++---- tests/task-1-spec.rb | 48 ++ 32 files changed, 8048 insertions(+), 140 deletions(-) create mode 100644 .byebug_history create mode 100644 result.json create mode 100644 ruby-prof-callgrind.rb create mode 100644 ruby-prof-callstack.rb create mode 100644 ruby-prof-flat.rb create mode 100644 ruby_prof_reports/callgrind.out.1 create mode 100644 ruby_prof_reports/callgrind.out.2 create mode 100644 ruby_prof_reports/callgrind.out.3 create mode 100644 ruby_prof_reports/callgrind.out.4 create mode 100644 ruby_prof_reports/callgrind.out.5 create mode 100644 ruby_prof_reports/callgrind.out.6 create mode 100644 ruby_prof_reports/callgrind.out.7 create mode 100644 ruby_prof_reports/callstack1.html create mode 100644 ruby_prof_reports/callstack2.html create mode 100644 ruby_prof_reports/callstack3.html create mode 100644 ruby_prof_reports/callstack4.html create mode 100644 ruby_prof_reports/callstack6.html create mode 100644 ruby_prof_reports/callstack7.html create mode 100644 ruby_prof_reports/flat1.txt create mode 100644 ruby_prof_reports/flat2.txt create mode 100644 ruby_prof_reports/flat3.txt create mode 100644 ruby_prof_reports/flat4.txt create mode 100644 ruby_prof_reports/flat5.txt create mode 100644 ruby_prof_reports/flat6.txt create mode 100644 ruby_prof_reports/flat7.txt create mode 100644 stackprof-speedscope.rb create mode 100644 stackprof.rb create mode 100644 stackprof_reports/stackprof.dump create mode 100644 stackprof_reports/stackprof.json create mode 100644 tests/task-1-spec.rb diff --git a/.byebug_history b/.byebug_history new file mode 100644 index 00000000..2e94e425 --- /dev/null +++ b/.byebug_history @@ -0,0 +1,64 @@ +continue +report +report['usersStats'][user_key] ||= {} +user_key = "#{user['first_name']} #{user['last_name']}" +report +stats +user +continue +report +report['usersStats'][user_key] = report['usersStats'][user_key].merge(stats) +report +report['usersStats'][user_key] ||= {} +report +user_key = "#{user['first_name']} #{user['last_name']}" +stats +sessions.select('pluck') +sessions.pluck('time') +time_sessions = sessions.map { |s| s['time'] }.map(&:to_i) +sessions.count +sessions +continue +report +collect_stats_for_user(report, u, sessions[u['id']]) +report +collect_stats_for_user(report, u, sessions[u['id']]) +u = users.first +users +pp sessions["0"] +sessions["0"] +sessions +continue +sessions["0"] +sessions +line +continue +line +continue +sessions +line +continue +line +sessions +continue +sessions +current_user +continue +current_user +user +sessions["0"] +sessions +line +continue +line +continue +sessions +line +continue +line +continue +line +continue +line +continue +line diff --git a/case-study-template.md b/case-study-template.md index d41034d9..f1ba4149 100644 --- a/case-study-template.md +++ b/case-study-template.md @@ -12,7 +12,9 @@ Я решил исправить эту проблему, оптимизировав эту программу. ## Формирование метрики -Для того, чтобы понимать, дают ли мои изменения положительный эффект на быстродействие программы я придумал использовать такую метрику: *тут ваша метрика* +Для того, чтобы понимать, дают ли мои изменения положительный эффект на быстродействие программы я придумал использовать такую метрику: +изначально дождаться выполнения скрипта на больших данных не удалось, поэтому непонятно каким должен быть бюджет в плане сложности. +для начала сделаю так, чтобы данные были обработаны в течение, хотя бы, минуты. ## Гарантия корректности работы оптимизированной программы Программа поставлялась с тестом. Выполнение этого теста в фидбек-лупе позволяет не допустить изменения логики программы при оптимизации. @@ -20,37 +22,66 @@ ## Feedback-Loop Для того, чтобы иметь возможность быстро проверять гипотезы я выстроил эффективный `feedback-loop`, который позволил мне получать обратную связь по эффективности сделанных изменений за *время, которое у вас получилось* -Вот как я построил `feedback_loop`: *как вы построили feedback_loop* +Вот как я построил `feedback_loop`: сначала выделить тест в отдельный файл. запустить профилировщики, посмотреть на самые тяжеловесные вычисления, +попробовать их оптимизировать, запустить тест, проверить метрики. ## Вникаем в детали системы, чтобы найти главные точки роста -Для того, чтобы найти "точки роста" для оптимизации я воспользовался *инструментами, которыми вы воспользовались* +Для того, чтобы найти "точки роста" для оптимизации я воспользовался профилировщиками. rbspy установить не получилось, +какие то проблемы с зависимостями glibc на mint 20.3, stackprof выдал пустой результат, +а ruby-prof оказался полезен. особо callgrind Вот какие проблемы удалось найти и решить ### Ваша находка №1 -- какой отчёт показал главную точку роста -- как вы решили её оптимизировать -- как изменилась метрика -- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? +- Больше всего времени(21%) занимает метод collect_stats_from_users, в частности Date.parse все тормозит. +- Посмотрел входные данные - увидел, что формат даты всегда одинаковый. значит вместо Date.parse можно использовать парсер, которому не нужно угадывать формат. + Заменил Date.parse(d) на Date.new(*d.split('-')) +- парсинг даты теперь не занимает времени совсем, и переместился с 1 места на 6, но чуть чуть прибавилось времени у split +- вроде норм, перейдем к другим проблемам ### Ваша находка №2 -- какой отчёт показал главную точку роста -- как вы решили её оптимизировать -- как изменилась метрика -- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? - -### Ваша находка №X -- какой отчёт показал главную точку роста -- как вы решили её оптимизировать -- как изменилась метрика -- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? +- теперь больше всего времени занимают IO операции, read(16%) и write(14%) +- для вывода данных выбран формат json. можно попробовать сделать это с помощью библиотеки oj. + для записи данных использовал Oj.to_file('result.json', report, mode: :compat) + для чтения попробую использовать readlines +- значительных изменений нет +- IO::read осталось то же, IO::write даже увеличилось. мне кажется это нельзя изменить, поэтому нужно выбрать другую точку роста + +### Ваша находка №3 +- collect_stats_from_users вызывается 7 раз и занимает 33% времени. с помощью kcachegrind увидел, что в нем много раз вызывается map +- кажется, что метод много раз вызывается на одних и тех же данных. это похоже на n+1. порефакторим. +- доля array#each уменьшилась с 13% до 6, +- незначительно уменьшил долю each в общем выполнении + +### Ваша находка №4 +- что если не нужно ждать окончания readlines, после которого выполнять обработку данных, а сразу выполнять обработку? + получается читаем строку, сразу же ее обрабатываем - не нужно будет позже подгружать пользователя и все сессии. + когда блок сессий закончится, эти же данные можно записать в файл, но это выглядит сложно, и проблема ведь не в памяти? + можно начать с оптимизации подсчета статистик. например убрать .all? , использовать set для проверки уникальности браузеров +- почему-то во flat.txt не указывается IO::write. время выполнения уменьшилось на 300мс. но тк из 500 прошлых 24% занимал IO::write, а это около 100, + то можно считать, что улучшилось на 200. set реально работает + +### Ваша находка №5 + - помимо метода readlines оставшееся время съедает некий Array.each... их в общем то в коде много, надо подумать как уменьшить проходы по спискам + - each это линейная операция, значит нужно взять что-то лучше. бинпоиск не поможет тк сначала данные нужно отсортировать, у нас нет на это времени. + можно взять хеш, у него время доступа O(1). осталось придумать только в каких местах можно его применить. + на первый взгляд можно убрать отдельный цикл sessions.each для подсчета браузеров. сделать это внутри readlines + - доля времени write выросла, each уменьшилась. большой файл все еще не читается + +### Ваша находка №6 + - в цикле users.each происходит еще один цикл users.select. это я глазом заметил и тут я начинаю подозревать, что ruby_prof мне выдает просто рандомные числа, + потому что за последние несколько раз метрики то пропадали, но давали странные значения. и у всех абсолютное время 0 + - формирование сессий можно вынести так же в цикл чтения. заменил список sessions на хеш. тогда нам вообще не нужен класс user и список users_objects + - как изменилась метрика? а я не понял, потому что она не изменилась, но теперь большой файл возможно обработать. надо мне пошаманить с профилировщиками + единственное полезное на что мне указал ruby_prof это Date.parse, а то что Array.each занимает много времени мне ни о чем не говорит ## Результаты В результате проделанной оптимизации наконец удалось обработать файл с данными. -Удалось улучшить метрику системы с *того, что у вас было в начале, до того, что получилось в конце* и уложиться в заданный бюджет. +Удалось улучшить метрику системы с того, что большой файл обработать не получалось, до того, что получилось ¯\_(ツ)_/¯ *Какими ещё результами можете поделиться* ## Защита от регрессии производительности -Для защиты от потери достигнутого прогресса при дальнейших изменениях программы *о performance-тестах, которые вы написали* - +Для защиты от потери достигнутого прогресса при дальнейших изменениях программы добавил тест, проверяющий выполняется ли программа менее чем за минуту. +сначала думал что норм тест, а потом подождал - не норм. представил проект, в котором все тесты такие. надо подумать как уменьшить объем данных +чисто для теста. но это попозже, сейчас я устал diff --git a/result.json b/result.json new file mode 100644 index 00000000..ad485631 --- /dev/null +++ b/result.json @@ -0,0 +1 @@ +{"totalUsers":3,"uniqueBrowsersCount":14,"totalSessions":15,"allBrowsers":"CHROME 13,CHROME 20,CHROME 35,CHROME 6,FIREFOX 12,FIREFOX 32,FIREFOX 47,INTERNET EXPLORER 10,INTERNET EXPLORER 28,INTERNET EXPLORER 35,SAFARI 17,SAFARI 29,SAFARI 39,SAFARI 49","usersStats":{"Leida Cira":{"sessionsCount":6,"totalTime":"455 min.","longestSession":"118 min.","browsers":"FIREFOX 12, INTERNET EXPLORER 28, INTERNET EXPLORER 28, INTERNET EXPLORER 35, SAFARI 29, SAFARI 39","usedIE":true,"alwaysUsedChrome":false,"dates":["2017-09-27","2017-03-28","2017-02-27","2016-10-23","2016-09-15","2016-09-01"]},"Palmer Katrina":{"sessionsCount":5,"totalTime":"218 min.","longestSession":"116 min.","browsers":"CHROME 13, CHROME 6, FIREFOX 32, INTERNET EXPLORER 10, SAFARI 17","usedIE":true,"alwaysUsedChrome":false,"dates":["2017-04-29","2016-12-28","2016-12-20","2016-11-11","2016-10-21"]},"Gregory Santos":{"sessionsCount":4,"totalTime":"192 min.","longestSession":"85 min.","browsers":"CHROME 20, CHROME 35, FIREFOX 47, SAFARI 49","usedIE":false,"alwaysUsedChrome":false,"dates":["2018-09-21","2018-02-02","2017-05-22","2016-11-25"]}}} diff --git a/ruby-prof-callgrind.rb b/ruby-prof-callgrind.rb new file mode 100644 index 00000000..ad61b837 --- /dev/null +++ b/ruby-prof-callgrind.rb @@ -0,0 +1,11 @@ +require 'ruby-prof' +require_relative 'task-1' + +RubyProf.measure_mode = RubyProf::WALL_TIME + +result = RubyProf.profile do + work(path: 'data.txt', disable_gc: true) +end + +printer4 = RubyProf::CallTreePrinter.new(result) +printer4.print(:path => "ruby_prof_reports", :profile => 'callgrind') diff --git a/ruby-prof-callstack.rb b/ruby-prof-callstack.rb new file mode 100644 index 00000000..69e66517 --- /dev/null +++ b/ruby-prof-callstack.rb @@ -0,0 +1,11 @@ +require 'ruby-prof' +require_relative 'task-1' + +RubyProf.measure_mode = RubyProf::WALL_TIME + +result = RubyProf.profile do + work(path: 'data.txt', disable_gc: true) +end + +printer = RubyProf::CallStackPrinter.new(result) +printer.print(File.open('ruby_prof_reports/callstack.html', 'w+')) diff --git a/ruby-prof-flat.rb b/ruby-prof-flat.rb new file mode 100644 index 00000000..a1f23b06 --- /dev/null +++ b/ruby-prof-flat.rb @@ -0,0 +1,10 @@ +require 'ruby-prof' +require_relative 'task-1' + +RubyProf.measure_mode = RubyProf::WALL_TIME + +result = RubyProf.profile do + work(path: 'data.txt', disable_gc: true) +end +printer = RubyProf::FlatPrinter.new(result) +printer.print(File.open("ruby_prof_reports/flat.txt", "w+")) diff --git a/ruby_prof_reports/callgrind.out.1 b/ruby_prof_reports/callgrind.out.1 new file mode 100644 index 00000000..43823f4a --- /dev/null +++ b/ruby_prof_reports/callgrind.out.1 @@ -0,0 +1,274 @@ +events: wall_time + +fl= +fn=Exception::backtrace +0 1 + +fl= +fn=Exception::exception +0 1 + +fl= +fn=Exception::initialize +0 1 + +fl= +fn=Date::initialize +0 10 +cfl= +cfn=Exception::initialize +calls=1 0 +0 1 +cfl= +cfn=Exception::exception +calls=1 0 +0 1 +cfl= +cfn=Exception::backtrace +calls=1 0 +0 1 + +fl= +fn=Array::any? +0 7 +cfl= +cfn=String::upcase +calls=11 129 +129 2 + +fl= +fn=Array::max +0 1 + +fl= +fn=String::+ +0 2 + +fl= +fn=Integer::to_s +0 2 + +fl= +fn=Array::sum +0 1 + +fl= +fn=String::to_i +0 5 + +fl= +fn=Hash::merge +0 6 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::collect_stats_from_users +39 3 +cfl= +cfn=Array::each +calls=7 40 +40 116 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=User::initialize +12 2 + +fl= +fn=Class::new +0 5 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=User::initialize +calls=3 0 +0 2 +cfl= +cfn=Date::initialize +calls=1 0 +0 12 + +fl= +fn=Array::select +0 9 + +fl= +fn=Array::join +0 5 + +fl= +fn=Array::uniq +0 2 + +fl= +fn=Array::sort +0 5 + +fl= +fn=String::upcase +0 9 + +fl= +fn=Array::map +0 34 +cfl= +cfn=String::upcase +calls=30 90 +90 6 +cfl= +cfn=String::to_i +calls=30 114 +114 5 +cfl= +cfn=String::split +calls=1 139 +139 1 +cfl= +cfn=Class::new +calls=1 139 +139 14 + +fl= +fn=Array::all? +0 17 +cfl= +cfn=String::upcase +calls=4 134 +134 1 + +fl= +fn=Array::count +0 1 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::parse_session +28 11 +cfl= +cfn=String::split +calls=15 29 +29 10 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::parse_user +18 3 +cfl= +cfn=String::split +calls=3 19 +19 2 + +fl= +fn=String::split +0 26 + +fl= +fn=Array::each +0 64 +cfl= +cfn=String::split +calls=18 52 +52 13 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::parse_user +calls=3 53 +53 5 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::parse_session +calls=15 54 +54 21 +cfl= +cfn=Array::all? +calls=18 80 +80 17 +cfl= +cfn=Array::select +calls=3 100 +100 9 +cfl= +cfn=Class::new +calls=3 101 +101 6 +cfl= +cfn=Array::count +calls=3 109 +109 1 +cfl= +cfn=Hash::merge +calls=18 109 +109 6 +cfl= +cfn=Array::map +calls=26 114 +114 50 +cfl= +cfn=Array::sum +calls=3 114 +114 1 +cfl= +cfn=Integer::to_s +calls=6 114 +114 2 +cfl= +cfn=String::+ +calls=6 114 +114 2 +cfl= +cfn=Array::max +calls=3 119 +119 1 +cfl= +cfn=Array::sort +calls=3 124 +124 2 +cfl= +cfn=Array::join +calls=3 124 +124 3 +cfl= +cfn=Array::any? +calls=3 129 +129 9 + +fl= +fn=IO::readlines^ +0 74 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::work +47 12 +cfl= +cfn=IO::readlines^ +calls=1 51 +51 74 +cfl= +cfn=Array::each +calls=3 51 +51 94 +cfl= +cfn=Array::count +calls=3 74 +74 1 +cfl= +cfn=Array::map +calls=2 87 +87 9 +cfl= +cfn=Array::sort +calls=1 87 +87 3 +cfl= +cfn=Array::uniq +calls=1 87 +87 2 +cfl= +cfn=Array::join +calls=1 87 +87 2 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::collect_stats_from_users +calls=7 108 +108 119 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/ruby-prof-callgrind.rb +fn=[global]:: +7 16 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::work +calls=1 7 +7 316 + diff --git a/ruby_prof_reports/callgrind.out.2 b/ruby_prof_reports/callgrind.out.2 new file mode 100644 index 00000000..8f5d9b4f --- /dev/null +++ b/ruby_prof_reports/callgrind.out.2 @@ -0,0 +1,302 @@ +events: wall_time + +fl= +fn=IO::write^ +0 113 + +fl= +fn=JSON/Ext/Generator/State::initialize +0 1 + +fl= +fn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json +0 14 +cfl= +cfn=JSON/Ext/Generator/State::initialize +calls=1 0 +0 1 + +fl= +fn=Date::iso8601 +0 11 + +fl= +fn=Array::reverse +0 1 + +fl= +fn=Date::<=> +0 5 + +fl= +fn=Integer::div +0 3 + +fl= +fn=Date::strptime^ +0 35 +cfl= +cfn=Integer::div +calls=15 0 +0 3 + +fl= +fn=Array::any? +0 7 +cfl= +cfn=String::upcase +calls=11 129 +129 2 + +fl= +fn=Array::max +0 1 + +fl= +fn=String::+ +0 2 + +fl= +fn=Integer::to_s +0 2 + +fl= +fn=Array::sum +0 1 + +fl= +fn=String::to_i +0 5 + +fl= +fn=Hash::merge +0 6 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::collect_stats_from_users +37 3 +cfl= +cfn=Array::each +calls=7 38 +38 184 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=User::initialize +10 3 + +fl= +fn=Class::new +0 3 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=User::initialize +calls=3 0 +0 3 + +fl= +fn=Array::select +0 9 + +fl= +fn=Array::join +0 4 + +fl= +fn=Array::uniq +0 2 + +fl= +fn=Array::sort +0 10 +cfl= +cfn=Date::<=> +calls=21 0 +0 5 + +fl= +fn=String::upcase +0 9 + +fl= +fn=Array::map +0 46 +cfl= +cfn=String::upcase +calls=30 90 +90 6 +cfl= +cfn=String::to_i +calls=30 114 +114 5 +cfl= +cfn=Date::strptime^ +calls=15 139 +139 38 +cfl= +cfn=Date::iso8601 +calls=15 139 +139 11 + +fl= +fn=Array::all? +0 17 +cfl= +cfn=String::upcase +calls=4 134 +134 1 + +fl= +fn=Array::count +0 2 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::parse_session +26 10 +cfl= +cfn=String::split +calls=15 27 +27 9 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::parse_user +16 3 +cfl= +cfn=String::split +calls=3 17 +17 3 + +fl= +fn=Array::each +0 73 +cfl= +cfn=String::split +calls=18 52 +52 12 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::parse_user +calls=3 53 +53 6 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::parse_session +calls=15 54 +54 19 +cfl= +cfn=Array::all? +calls=18 80 +80 18 +cfl= +cfn=Array::select +calls=3 100 +100 9 +cfl= +cfn=Class::new +calls=3 101 +101 6 +cfl= +cfn=Array::count +calls=3 109 +109 1 +cfl= +cfn=Hash::merge +calls=21 109 +109 6 +cfl= +cfn=Array::map +calls=33 114 +114 96 +cfl= +cfn=Array::sum +calls=3 114 +114 1 +cfl= +cfn=Integer::to_s +calls=6 114 +114 2 +cfl= +cfn=String::+ +calls=6 114 +114 2 +cfl= +cfn=Array::max +calls=3 119 +119 1 +cfl= +cfn=Array::sort +calls=6 124 +124 12 +cfl= +cfn=Array::join +calls=3 124 +124 2 +cfl= +cfn=Array::any? +calls=3 129 +129 9 +cfl= +cfn=Array::reverse +calls=3 139 +139 1 + +fl= +fn=String::split +0 28 + +fl= +fn=IO::read^ +0 86 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::work +45 16 +cfl= +cfn=IO::read^ +calls=1 46 +46 86 +cfl= +cfn=String::split +calls=1 46 +46 4 +cfl= +cfn=Array::each +calls=3 51 +51 92 +cfl= +cfn=Array::count +calls=3 74 +74 1 +cfl= +cfn=Array::map +calls=2 87 +87 10 +cfl= +cfn=Array::sort +calls=1 87 +87 3 +cfl= +cfn=Array::uniq +calls=1 87 +87 2 +cfl= +cfn=Array::join +calls=1 87 +87 2 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::collect_stats_from_users +calls=7 108 +108 188 +cfl= +cfn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json +calls=1 142 +142 15 +cfl= +cfn=IO::write^ +calls=1 142 +142 113 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/ruby-prof-callgrind.rb +fn=[global]:: +7 16 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::work +calls=1 7 +7 532 + diff --git a/ruby_prof_reports/callgrind.out.3 b/ruby_prof_reports/callgrind.out.3 new file mode 100644 index 00000000..288913a7 --- /dev/null +++ b/ruby_prof_reports/callgrind.out.3 @@ -0,0 +1,282 @@ +events: wall_time + +fl= +fn=Oj::to_file^ +0 144 + +fl= +fn=Date::iso8601 +0 12 + +fl= +fn=Array::reverse +0 1 + +fl= +fn=Date::<=> +0 5 + +fl= +fn=Integer::div +0 3 + +fl= +fn=Date::strptime^ +0 35 +cfl= +cfn=Integer::div +calls=15 0 +0 3 + +fl= +fn=Array::any? +0 7 +cfl= +cfn=String::upcase +calls=11 129 +129 2 + +fl= +fn=Array::max +0 1 + +fl= +fn=String::+ +0 2 + +fl= +fn=Integer::to_s +0 2 + +fl= +fn=Array::sum +0 1 + +fl= +fn=String::to_i +0 5 + +fl= +fn=Hash::merge +0 7 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::collect_stats_from_users +39 3 +cfl= +cfn=Array::each +calls=7 40 +40 177 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=User::initialize +12 2 + +fl= +fn=Class::new +0 3 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=User::initialize +calls=3 0 +0 2 + +fl= +fn=Array::select +0 9 + +fl= +fn=Array::join +0 5 + +fl= +fn=Array::uniq +0 2 + +fl= +fn=Array::sort +0 10 +cfl= +cfn=Date::<=> +calls=21 0 +0 5 + +fl= +fn=String::upcase +0 9 + +fl= +fn=Array::map +0 44 +cfl= +cfn=String::upcase +calls=30 90 +90 6 +cfl= +cfn=String::to_i +calls=30 114 +114 5 +cfl= +cfn=Date::strptime^ +calls=15 139 +139 38 +cfl= +cfn=Date::iso8601 +calls=15 139 +139 12 + +fl= +fn=Array::all? +0 16 +cfl= +cfn=String::upcase +calls=4 134 +134 1 + +fl= +fn=Array::count +0 2 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::parse_session +28 10 +cfl= +cfn=String::split +calls=15 29 +29 10 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::parse_user +18 3 +cfl= +cfn=String::split +calls=3 19 +19 2 + +fl= +fn=String::split +0 25 + +fl= +fn=Array::each +0 65 +cfl= +cfn=String::split +calls=18 52 +52 13 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::parse_user +calls=3 53 +53 5 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::parse_session +calls=15 54 +54 20 +cfl= +cfn=Array::all? +calls=18 80 +80 17 +cfl= +cfn=Array::select +calls=3 100 +100 9 +cfl= +cfn=Class::new +calls=3 101 +101 6 +cfl= +cfn=Array::count +calls=3 109 +109 1 +cfl= +cfn=Hash::merge +calls=21 109 +109 7 +cfl= +cfn=Array::map +calls=33 114 +114 96 +cfl= +cfn=Array::sum +calls=3 114 +114 1 +cfl= +cfn=Integer::to_s +calls=6 114 +114 2 +cfl= +cfn=String::+ +calls=6 114 +114 2 +cfl= +cfn=Array::max +calls=3 119 +119 1 +cfl= +cfn=Array::sort +calls=6 124 +124 12 +cfl= +cfn=Array::join +calls=3 124 +124 3 +cfl= +cfn=Array::any? +calls=3 129 +129 9 +cfl= +cfn=Array::reverse +calls=3 139 +139 1 + +fl= +fn=IO::readlines^ +0 78 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::work +47 14 +cfl= +cfn=IO::readlines^ +calls=1 51 +51 78 +cfl= +cfn=Array::each +calls=3 51 +51 91 +cfl= +cfn=Array::count +calls=3 74 +74 1 +cfl= +cfn=Array::map +calls=2 87 +87 9 +cfl= +cfn=Array::sort +calls=1 87 +87 3 +cfl= +cfn=Array::uniq +calls=1 87 +87 2 +cfl= +cfn=Array::join +calls=1 87 +87 2 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::collect_stats_from_users +calls=7 108 +108 180 +cfl= +cfn=Oj::to_file^ +calls=1 143 +143 144 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/ruby-prof-callgrind.rb +fn=[global]:: +7 17 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::work +calls=1 7 +7 524 + diff --git a/ruby_prof_reports/callgrind.out.4 b/ruby_prof_reports/callgrind.out.4 new file mode 100644 index 00000000..af2908cb --- /dev/null +++ b/ruby_prof_reports/callgrind.out.4 @@ -0,0 +1,298 @@ +events: wall_time + +fl= +fn=IO::write^ +0 113 + +fl= +fn=Oj::dump^ +0 20 + +fl= +fn=Hash::merge +0 4 + +fl= +fn=Date::iso8601 +0 12 + +fl= +fn=Array::reverse +0 1 + +fl= +fn=Date::<=> +0 5 + +fl= +fn=Date::initialize +0 10 + +fl= +fn=String::include? +0 5 + +fl= +fn=Array::any? +0 5 +cfl= +cfn=String::upcase +calls=11 57 +57 2 +cfl= +cfn=String::include? +calls=11 57 +57 3 + +fl= +fn=Array::max +0 1 + +fl= +fn=Integer::to_s +0 2 + +fl= +fn=Array::sum +0 1 + +fl= +fn=String::to_i +0 9 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +fn=Object::collect_all_stats +47 20 +cfl= +cfn=Array::map +calls=21 49 +49 88 +cfl= +cfn=Array::count +calls=3 53 +53 1 +cfl= +cfn=Array::sum +calls=3 53 +53 1 +cfl= +cfn=Integer::to_s +calls=6 53 +53 2 +cfl= +cfn=Array::max +calls=3 53 +53 1 +cfl= +cfn=Array::sort +calls=6 53 +53 12 +cfl= +cfn=Array::join +calls=3 53 +53 2 +cfl= +cfn=Array::any? +calls=3 53 +53 11 +cfl= +cfn=Array::all? +calls=3 53 +53 5 +cfl= +cfn=Array::reverse +calls=3 53 +53 1 +cfl= +cfn=Hash::merge +calls=3 64 +64 4 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +fn=User::initialize +12 3 + +fl= +fn=Class::new +0 10 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +cfn=User::initialize +calls=3 0 +0 3 +cfl= +cfn=Date::initialize +calls=15 0 +0 10 + +fl= +fn=Array::select +0 9 + +fl= +fn=Array::join +0 5 + +fl= +fn=Array::uniq +0 2 + +fl= +fn=Array::sort +0 10 +cfl= +cfn=Date::<=> +calls=21 0 +0 5 + +fl= +fn=String::upcase +0 9 + +fl= +fn=Array::map +0 45 +cfl= +cfn=String::upcase +calls=30 0 +0 6 +cfl= +cfn=String::to_i +calls=60 0 +0 9 +cfl= +cfn=String::split +calls=15 59 +59 8 +cfl= +cfn=Array::map +calls=15 59 +59 16 +cfl= +cfn=Class::new +calls=15 59 +59 17 +cfl= +cfn=Date::iso8601 +calls=15 0 +0 12 + +fl= +fn=Array::all? +0 17 +cfl= +cfn=String::upcase +calls=4 58 +58 1 +cfl= +cfn=String::include? +calls=4 58 +58 2 + +fl= +fn=Array::count +0 2 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +fn=Object::parse_session +28 11 +cfl= +cfn=String::split +calls=15 29 +29 10 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +fn=Object::parse_user +18 3 +cfl= +cfn=String::split +calls=3 19 +19 2 + +fl= +fn=String::split +0 32 + +fl= +fn=Array::each +0 29 +cfl= +cfn=String::split +calls=18 72 +72 13 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +cfn=Object::parse_user +calls=3 73 +73 5 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +cfn=Object::parse_session +calls=15 74 +74 21 +cfl= +cfn=Array::all? +calls=15 100 +100 14 +cfl= +cfn=Array::select +calls=3 120 +120 9 +cfl= +cfn=Class::new +calls=3 121 +121 6 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +cfn=Object::collect_all_stats +calls=3 127 +127 148 + +fl= +fn=IO::readlines^ +0 73 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +fn=Object::work +67 13 +cfl= +cfn=IO::readlines^ +calls=1 71 +71 73 +cfl= +cfn=Array::each +calls=4 71 +71 244 +cfl= +cfn=Array::count +calls=3 94 +94 1 +cfl= +cfn=Array::map +calls=2 107 +107 9 +cfl= +cfn=Array::sort +calls=1 107 +107 3 +cfl= +cfn=Array::uniq +calls=1 107 +107 2 +cfl= +cfn=Array::join +calls=1 107 +107 2 +cfl= +cfn=Oj::dump^ +calls=1 164 +164 20 +cfl= +cfn=IO::write^ +calls=1 164 +164 113 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/ruby-prof-callgrind.rb +fn=[global]:: +7 16 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +cfn=Object::work +calls=1 7 +7 480 + diff --git a/ruby_prof_reports/callgrind.out.5 b/ruby_prof_reports/callgrind.out.5 new file mode 100644 index 00000000..3004bd9e --- /dev/null +++ b/ruby_prof_reports/callgrind.out.5 @@ -0,0 +1,166 @@ +events: wall_time + +fl= +fn=Exception::backtrace +0 1 + +fl= +fn=Exception::exception +0 0 + +fl= +fn=BasicObject::method_missing +0 4 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +fn=User::initialize +12 3 + +fl= +fn=Class::new +0 3 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +cfn=User::initialize +calls=3 0 +0 3 + +fl= +fn=Array::select +0 9 + +fl= +fn=Array::join +0 2 + +fl= +fn=Array::uniq +0 2 + +fl= +fn=Array::sort +0 3 + +fl= +fn=String::upcase +0 3 + +fl= +fn=Array::map +0 6 +cfl= +cfn=String::upcase +calls=15 0 +0 3 + +fl= +fn=Array::all? +0 14 + +fl= +fn=Array::count +0 1 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +fn=Object::parse_session +28 11 +cfl= +cfn=String::split +calls=15 29 +29 10 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +fn=Object::parse_user +18 3 +cfl= +cfn=String::split +calls=3 19 +19 2 + +fl= +fn=String::split +0 25 + +fl= +fn=Array::each +0 32 +cfl= +cfn=String::split +calls=18 54 +54 13 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +cfn=Object::parse_user +calls=3 55 +55 5 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +cfn=Object::parse_session +calls=15 56 +56 21 +cfl= +cfn=Array::all? +calls=15 82 +82 14 +cfl= +cfn=Array::select +calls=3 102 +102 9 +cfl= +cfn=Class::new +calls=3 103 +103 6 +cfl= +cfn=BasicObject::method_missing +calls=1 109 +109 4 +cfl= +cfn=Exception::exception +calls=1 109 +109 0 +cfl= +cfn=Exception::backtrace +calls=1 109 +109 1 + +fl= +fn=IO::readlines^ +0 79 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +fn=Object::work +49 10 +cfl= +cfn=IO::readlines^ +calls=1 53 +53 79 +cfl= +cfn=Array::each +calls=4 53 +53 105 +cfl= +cfn=Array::count +calls=3 76 +76 1 +cfl= +cfn=Array::map +calls=2 89 +89 10 +cfl= +cfn=Array::sort +calls=1 89 +89 3 +cfl= +cfn=Array::uniq +calls=1 89 +89 2 +cfl= +cfn=Array::join +calls=1 89 +89 2 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/ruby-prof-callgrind.rb +fn=[global]:: +7 15 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb +cfn=Object::work +calls=1 7 +7 212 + diff --git a/ruby_prof_reports/callgrind.out.6 b/ruby_prof_reports/callgrind.out.6 new file mode 100644 index 00000000..207c9845 --- /dev/null +++ b/ruby_prof_reports/callgrind.out.6 @@ -0,0 +1,290 @@ +events: wall_time + +fl= +fn=IO::write^ +0 107 + +fl= +fn=Oj::dump^ +0 19 + +fl= +fn=Hash::merge +0 3 + +fl= +fn=Array::reverse +0 1 + +fl= +fn=Array::all? +0 1 + +fl= +fn=Array::any? +0 1 + +fl= +fn=Array::sort +0 2 + +fl= +fn=NilClass::to_s +0 1 + +fl= +fn=Array::max +0 1 + +fl= +fn=Integer::to_s +0 1 + +fl= +fn=Array::sum +0 1 + +fl= +fn=Array::map +0 3 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::collect_all_stats +40 18 +cfl= +cfn=Array::map +calls=21 42 +42 3 +cfl= +cfn=Array::count +calls=3 46 +46 1 +cfl= +cfn=Array::sum +calls=3 46 +46 1 +cfl= +cfn=Integer::to_s +calls=3 46 +46 1 +cfl= +cfn=Array::max +calls=3 46 +46 1 +cfl= +cfn=NilClass::to_s +calls=3 46 +46 1 +cfl= +cfn=Array::sort +calls=6 46 +46 2 +cfl= +cfn=Array::join +calls=3 46 +46 1 +cfl= +cfn=Array::any? +calls=3 46 +46 1 +cfl= +cfn=Array::all? +calls=3 46 +46 1 +cfl= +cfn=Array::reverse +calls=3 46 +46 1 +cfl= +cfn=Hash::merge +calls=3 57 +57 3 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=User::initialize +13 2 + +fl= +fn=Array::select +0 1 + +fl= +fn=Array::join +0 3 + +fl= +fn=Hash::each_key +0 2 + +fl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +fn=Set::each +326 2 +cfl= +cfn=Hash::each_key +calls=1 328 +328 2 + +fl= +fn=Enumerable::sort +0 4 +cfl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +cfn=Set::each +calls=1 0 +0 4 + +fl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +fn=Set::size +151 1 + +fl= +fn=Array::count +0 1 + +fl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +fn=Set::add +338 10 + +fl= +fn=String::upcase +0 4 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::parse_session +29 11 +cfl= +cfn=String::split +calls=15 30 +30 10 + +fl= +fn=String::split +0 13 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::parse_user +19 3 +cfl= +cfn=String::split +calls=3 20 +20 3 + +fl= +fn=String::[] +0 7 + +fl= +fn=Array::each +0 28 +cfl= +cfn=String::[] +calls=36 66 +66 7 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::parse_user +calls=3 67 +67 6 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::parse_session +calls=15 72 +72 21 +cfl= +cfn=String::upcase +calls=15 73 +73 4 +cfl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +cfn=Set::add +calls=15 73 +73 10 +cfl= +cfn=Array::select +calls=3 109 +109 1 +cfl= +cfn=Class::new +calls=3 110 +110 5 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::collect_all_stats +calls=3 116 +116 34 + +fl= +fn=IO::readlines^ +0 71 + +fl= +fn=Hash::initialize +0 1 + +fl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +fn=Set::initialize +93 2 +cfl= +cfn=Class::new +calls=1 94 +94 2 + +fl= +fn=Class::new +0 6 +cfl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +cfn=Set::initialize +calls=1 0 +0 4 +cfl= +cfn=Hash::initialize +calls=1 0 +0 1 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=User::initialize +calls=3 0 +0 2 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::work +60 12 +cfl= +cfn=Class::new +calls=1 61 +61 6 +cfl= +cfn=IO::readlines^ +calls=1 65 +65 71 +cfl= +cfn=Array::each +calls=3 65 +65 116 +cfl= +cfn=Array::count +calls=2 94 +94 1 +cfl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +cfn=Set::size +calls=1 98 +98 1 +cfl= +cfn=Enumerable::sort +calls=1 102 +102 8 +cfl= +cfn=Array::join +calls=1 102 +102 2 +cfl= +cfn=Oj::dump^ +calls=1 118 +118 19 +cfl= +cfn=IO::write^ +calls=1 118 +118 107 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/ruby-prof-callgrind.rb +fn=[global]:: +7 18 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::work +calls=1 7 +7 342 + diff --git a/ruby_prof_reports/callgrind.out.7 b/ruby_prof_reports/callgrind.out.7 new file mode 100644 index 00000000..ce5f06ee --- /dev/null +++ b/ruby_prof_reports/callgrind.out.7 @@ -0,0 +1,326 @@ +events: wall_time + +fl= +fn=IO::write^ +0 135 + +fl= +fn=JSON/Ext/Generator/State::initialize +0 1 + +fl= +fn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json +0 14 +cfl= +cfn=JSON/Ext/Generator/State::initialize +calls=1 0 +0 1 + +fl= +fn=Date::iso8601 +0 13 + +fl= +fn=Array::reverse +0 1 + +fl= +fn=Date::<=> +0 5 + +fl= +fn=Date::initialize +0 10 + +fl= +fn=Array::all? +0 3 +cfl= +cfn=String::upcase +calls=4 41 +41 1 +cfl= +cfn=String::include? +calls=4 41 +41 2 + +fl= +fn=String::include? +0 5 + +fl= +fn=Array::any? +0 5 +cfl= +cfn=String::upcase +calls=11 40 +40 3 +cfl= +cfn=String::include? +calls=11 40 +40 3 + +fl= +fn=Array::sort +0 7 +cfl= +cfn=Date::<=> +calls=21 0 +0 5 + +fl= +fn=Array::max +0 1 + +fl= +fn=Integer::to_s +0 2 + +fl= +fn=Array::sum +0 1 + +fl= +fn=Array::count +0 1 + +fl= +fn=String::to_i +0 10 + +fl= +fn=Array::map +0 37 +cfl= +cfn=String::to_i +calls=60 0 +0 10 +cfl= +cfn=String::upcase +calls=15 0 +0 3 +cfl= +cfn=String::split +calls=15 42 +42 7 +cfl= +cfn=Array::map +calls=15 42 +42 16 +cfl= +cfn=Class::new +calls=15 42 +42 17 +cfl= +cfn=Date::iso8601 +calls=15 0 +0 13 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::collect_stats_for_user +32 16 +cfl= +cfn=Array::map +calls=21 33 +33 87 +cfl= +cfn=Array::count +calls=3 36 +36 1 +cfl= +cfn=Array::sum +calls=3 36 +36 1 +cfl= +cfn=Integer::to_s +calls=6 36 +36 2 +cfl= +cfn=Array::max +calls=3 36 +36 1 +cfl= +cfn=Array::sort +calls=6 36 +36 12 +cfl= +cfn=Array::join +calls=3 36 +36 2 +cfl= +cfn=Array::any? +calls=3 36 +36 11 +cfl= +cfn=Array::all? +calls=3 36 +36 5 +cfl= +cfn=Array::reverse +calls=3 36 +36 1 + +fl= +fn=Array::join +0 4 + +fl= +fn=Hash::each_key +0 2 + +fl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +fn=Set::each +326 2 +cfl= +cfn=Hash::each_key +calls=1 328 +328 2 + +fl= +fn=Enumerable::sort +0 4 +cfl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +cfn=Set::each +calls=1 0 +0 3 + +fl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +fn=Set::size +151 1 + +fl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +fn=Set::add +338 12 + +fl= +fn=String::upcase +0 10 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::parse_session +21 11 +cfl= +cfn=String::split +calls=15 22 +22 11 + +fl= +fn=String::split +0 22 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::parse_user +11 3 +cfl= +cfn=String::split +calls=3 12 +12 3 + +fl= +fn=String::[] +0 4 + +fl= +fn=Array::each +0 28 +cfl= +cfn=String::[] +calls=18 58 +58 4 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::parse_user +calls=3 60 +60 6 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::parse_session +calls=15 65 +65 23 +cfl= +cfn=String::upcase +calls=15 68 +68 4 +cfl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +cfn=Set::add +calls=15 68 +68 12 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::collect_stats_for_user +calls=3 102 +102 139 + +fl= +fn=IO::readlines^ +0 68 + +fl= +fn=Hash::initialize +0 1 + +fl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +fn=Set::initialize +93 2 +cfl= +cfn=Class::new +calls=1 94 +94 2 + +fl= +fn=Class::new +0 10 +cfl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +cfn=Set::initialize +calls=1 0 +0 4 +cfl= +cfn=Hash::initialize +calls=1 0 +0 1 +cfl= +cfn=Date::initialize +calls=15 0 +0 10 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +fn=Object::work +49 11 +cfl= +cfn=Class::new +calls=1 50 +50 6 +cfl= +cfn=IO::readlines^ +calls=1 57 +57 68 +cfl= +cfn=Array::each +calls=2 57 +57 216 +cfl=/home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb +cfn=Set::size +calls=1 93 +93 1 +cfl= +cfn=Enumerable::sort +calls=1 97 +97 7 +cfl= +cfn=Array::join +calls=1 97 +97 2 +cfl= +cfn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json +calls=1 105 +105 14 +cfl= +cfn=IO::write^ +calls=1 105 +105 135 + +fl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/ruby-prof-callgrind.rb +fn=[global]:: +7 16 +cfl=/home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb +cfn=Object::work +calls=1 7 +7 460 + diff --git a/ruby_prof_reports/callstack1.html b/ruby_prof_reports/callstack1.html new file mode 100644 index 00000000..d2cd4e2c --- /dev/null +++ b/ruby_prof_reports/callstack1.html @@ -0,0 +1,902 @@ + + + + + ruby-prof call tree + + + + + + + +
+
+ Call tree for application ruby-prof-callstack.rb
Generated on 2023-10-22 02:08:43 +0300 + with options {}
+
+
+ Threshold: + + + + + +
+ + + + +
+ Thread: 80, Fiber: 60 (100.00% ~ 0.00035136999940732494) +
    + +
  • + +100.00% (100.00%) [global]# [1 calls, 1 total] +
      +
    • + +95.81% (95.81%) Object#work [1 calls, 1 total] +
        +
      • + +35.55% (37.11%) Object#collect_stats_from_users [7 calls, 7 total] +
          +
        • + +34.65% (97.46%) Array#each [7 calls, 10 total] +
            +
          • + +15.31% (44.19%) Array#map [26 calls, 28 total] +
              +
            • + +4.56% (29.75%) Class#new [1 calls, 4 total] +
                +
              • + +3.93% (86.36%) Date#initialize [1 calls, 1 total] +
                  + + + +
                +
              • +
              +
            • +
            • + +1.39% (9.07%) String#to_i [30 calls, 30 total] +
            • + + +
            +
          • +
          • + +2.79% (8.05%) Array#any? [3 calls, 3 total] +
              + +
            +
          • +
          • + +1.75% (5.05%) Hash#merge [18 calls, 18 total] +
          • +
          • + +1.03% (2.98%) Array#all? [3 calls, 18 total] +
              + +
            +
          • + + + + + + + +
          +
        • +
        +
      • +
      • + +27.67% (28.88%) Array#each [3 calls, 10 total] +
          +
        • + +5.91% (21.36%) Object#parse_session [15 calls, 15 total] +
            +
          • + +2.89% (48.84%) String#split [15 calls, 37 total] +
          • +
          +
        • +
        • + +3.96% (14.31%) Array#all? [15 calls, 18 total] +
        • +
        • + +3.94% (14.24%) String#split [18 calls, 37 total] +
        • +
        • + +2.56% (9.26%) Array#select [3 calls, 3 total] +
        • +
        • + +1.67% (6.03%) Class#new [3 calls, 4 total] + +
        • +
        • + +1.51% (5.47%) Object#parse_user [3 calls, 3 total] +
            + +
          +
        • +
        +
      • +
      • + +23.90% (24.95%) <Class::IO>#readlines [1 calls, 1 total] +
      • +
      • + +2.79% (2.91%) Array#map [2 calls, 28 total] +
          + +
        +
      • + + + + +
      +
    • +
    +
  • + +
+
+ +
+
+ + diff --git a/ruby_prof_reports/callstack2.html b/ruby_prof_reports/callstack2.html new file mode 100644 index 00000000..cf18b929 --- /dev/null +++ b/ruby_prof_reports/callstack2.html @@ -0,0 +1,916 @@ + + + + + ruby-prof call tree + + + + + + + +
+
+ Call tree for application ruby-prof-callstack.rb
Generated on 2023-10-22 00:59:52 +0300 + with options {}
+
+
+ Threshold: + + + + + +
+ + + + +
+ Thread: 80, Fiber: 60 (100.00% ~ 0.0006791470004827715) +
    + +
  • + +100.00% (100.00%) [global]# [1 calls, 1 total] +
      +
    • + +97.31% (97.31%) Object#work [1 calls, 1 total] +
        +
      • + +36.60% (37.61%) Object#collect_stats_from_users [7 calls, 7 total] +
          +
        • + +36.06% (98.52%) Array#each [7 calls, 10 total] +
            +
          • + +16.87% (46.80%) Array#map [33 calls, 35 total] +
              +
            • + +6.95% (41.21%) <Class::Date>#strptime [15 calls, 15 total] +
                + +
              +
            • +
            • + +1.85% (10.98%) Date#iso8601 [15 calls, 15 total] +
            • + + +
            +
          • +
          • + +5.09% (14.12%) Hash#merge [21 calls, 21 total] +
          • +
          • + +2.18% (6.05%) Array#sort [6 calls, 7 total] +
              + +
            +
          • +
          • + +1.46% (4.05%) Array#any? [3 calls, 3 total] +
              + +
            +
          • + + + + + + + + +
          +
        • +
        +
      • +
      • + +22.65% (23.27%) <Class::IO>#write [1 calls, 1 total] +
      • +
      • + +15.83% (16.27%) <Class::IO>#read [1 calls, 1 total] +
      • +
      • + +13.67% (14.05%) Array#each [3 calls, 10 total] +
          +
        • + +2.72% (19.93%) Object#parse_session [15 calls, 15 total] +
            +
          • + +1.24% (45.65%) String#split [15 calls, 37 total] +
          • +
          +
        • +
        • + +2.06% (15.06%) Array#all? [15 calls, 18 total] +
        • +
        • + +1.64% (12.02%) String#split [18 calls, 37 total] +
        • +
        • + +1.35% (9.86%) Array#select [3 calls, 3 total] +
        • + + +
        +
      • +
      • + +2.42% (2.48%) JSON::Ext::Generator::GeneratorMethods::Hash#to_json [1 calls, 1 total] +
          + +
        +
      • +
      • + +1.50% (1.54%) Array#map [2 calls, 35 total] +
          + +
        +
      • + + + + + +
      +
    • +
    +
  • + +
+
+ +
+
+ + diff --git a/ruby_prof_reports/callstack3.html b/ruby_prof_reports/callstack3.html new file mode 100644 index 00000000..aa840285 --- /dev/null +++ b/ruby_prof_reports/callstack3.html @@ -0,0 +1,902 @@ + + + + + ruby-prof call tree + + + + + + + +
+
+ Call tree for application ruby-prof-callstack.rb
Generated on 2023-10-22 01:54:42 +0300 + with options {}
+
+
+ Threshold: + + + + + +
+ + + + +
+ Thread: 80, Fiber: 60 (100.00% ~ 0.0005261839978629723) +
    + +
  • + +100.00% (100.00%) [global]# [1 calls, 1 total] +
      +
    • + +96.76% (96.76%) Object#work [1 calls, 1 total] +
        +
      • + +34.74% (35.90%) Object#collect_stats_from_users [7 calls, 7 total] +
          +
        • + +34.09% (98.14%) Array#each [7 calls, 10 total] +
            +
          • + +18.20% (53.39%) Array#map [33 calls, 35 total] +
              +
            • + +7.55% (41.49%) <Class::Date>#strptime [15 calls, 15 total] +
                + +
              +
            • +
            • + +1.82% (10.02%) Date#iso8601 [15 calls, 15 total] +
            • + + +
            +
          • +
          • + +2.30% (6.74%) Array#sort [6 calls, 7 total] +
              + +
            +
          • +
          • + +1.72% (5.04%) Array#any? [3 calls, 3 total] +
              + +
            +
          • +
          • + +1.25% (3.68%) Hash#merge [21 calls, 21 total] +
          • + + + + + + + + +
          +
        • +
        +
      • +
      • + +23.55% (24.34%) <Module::Oj>#to_file [1 calls, 1 total] +
      • +
      • + +17.70% (18.29%) Array#each [3 calls, 10 total] +
          +
        • + +3.87% (21.88%) Object#parse_session [15 calls, 15 total] +
            +
          • + +1.89% (48.85%) String#split [15 calls, 36 total] +
          • +
          +
        • +
        • + +2.61% (14.76%) Array#all? [15 calls, 18 total] +
        • +
        • + +2.53% (14.28%) String#split [18 calls, 36 total] +
        • +
        • + +1.64% (9.26%) Array#select [3 calls, 3 total] +
        • +
        • + +1.07% (6.03%) Class#new [3 calls, 3 total] + +
        • + +
        +
      • +
      • + +14.80% (15.29%) <Class::IO>#readlines [1 calls, 1 total] +
      • +
      • + +1.81% (1.87%) Array#map [2 calls, 35 total] +
          + +
        +
      • + + + + +
      +
    • +
    +
  • + +
+
+ +
+
+ + diff --git a/ruby_prof_reports/callstack4.html b/ruby_prof_reports/callstack4.html new file mode 100644 index 00000000..03d8cad8 --- /dev/null +++ b/ruby_prof_reports/callstack4.html @@ -0,0 +1,918 @@ + + + + + ruby-prof call tree + + + + + + + +
+
+ Call tree for application ruby-prof-callstack.rb
Generated on 2023-10-22 03:06:10 +0300 + with options {}
+
+
+ Threshold: + + + + + +
+ + + + +
+ Thread: 80, Fiber: 60 (100.00% ~ 0.00046213000314310193) +
    + +
  • + +100.00% (100.00%) [global]# [1 calls, 1 total] +
      +
    • + +96.70% (96.70%) Object#work [1 calls, 1 total] +
        +
      • + +52.58% (54.37%) Array#each [4 calls, 4 total] +
          +
        • + +31.82% (60.53%) Object#collect_all_stats [3 calls, 3 total] +
            +
          • + +18.77% (58.98%) Array#map [21 calls, 38 total] +
              +
            • + +3.68% (19.61%) Class#new [15 calls, 18 total] +
                +
              • + +2.18% (59.33%) Date#initialize [15 calls, 15 total] +
              • +
              +
            • +
            • + +3.58% (19.08%) Array#map [15 calls, 38 total] +
                +
              • + +1.49% (41.48%) String#to_i [45 calls, 60 total] +
              • +
              +
            • +
            • + +2.49% (13.26%) Date#iso8601 [15 calls, 15 total] +
            • +
            • + +1.70% (9.07%) String#split [15 calls, 51 total] +
            • + + +
            +
          • +
          • + +2.66% (8.36%) Array#sort [6 calls, 7 total] +
              +
            • + +1.10% (41.28%) Date#<=> [21 calls, 21 total] +
            • +
            +
          • +
          • + +2.32% (7.28%) Array#any? [3 calls, 3 total] +
              + + +
            +
          • +
          • + +1.10% (3.47%) Array#all? [3 calls, 18 total] +
              + + +
            +
          • + + + + + + + +
          +
        • +
        • + +4.40% (8.37%) Object#parse_session [15 calls, 15 total] +
            +
          • + +2.15% (48.98%) String#split [15 calls, 51 total] +
          • +
          +
        • +
        • + +3.04% (5.79%) Array#all? [15 calls, 18 total] +
        • +
        • + +2.90% (5.51%) String#split [18 calls, 51 total] +
        • +
        • + +1.96% (3.73%) Array#select [3 calls, 3 total] +
        • +
        • + +1.17% (2.23%) Class#new [3 calls, 18 total] + +
        • +
        • + +1.08% (2.06%) Object#parse_user [3 calls, 3 total] +
            + +
          +
        • +
        +
      • +
      • + +18.26% (18.88%) <Class::IO>#write [1 calls, 1 total] +
      • +
      • + +15.45% (15.97%) <Class::IO>#readlines [1 calls, 1 total] +
      • +
      • + +3.87% (4.00%) <Module::Oj>#dump [1 calls, 1 total] +
      • +
      • + +1.90% (1.96%) Array#map [2 calls, 38 total] +
          + +
        +
      • + + + + +
      +
    • +
    +
  • + +
+
+ +
+
+ + diff --git a/ruby_prof_reports/callstack6.html b/ruby_prof_reports/callstack6.html new file mode 100644 index 00000000..099333d2 --- /dev/null +++ b/ruby_prof_reports/callstack6.html @@ -0,0 +1,886 @@ + + + + + ruby-prof call tree + + + + + + + +
+
+ Call tree for application ruby-prof-callstack.rb
Generated on 2023-10-22 03:55:26 +0300 + with options {}
+
+
+ Threshold: + + + + + +
+ + + + +
+ Thread: 80, Fiber: 60 (100.00% ~ 0.00036810799792874604) +
    + +
  • + +100.00% (100.00%) [global]# [1 calls, 1 total] +
      +
    • + +95.48% (95.48%) Object#work [1 calls, 1 total] +
        +
      • + +31.65% (33.15%) Array#each [3 calls, 3 total] +
          +
        • + +9.34% (29.51%) Object#collect_all_stats [3 calls, 3 total] +
            + + + + + + + + + + + + +
          +
        • +
        • + +5.88% (18.58%) Object#parse_session [15 calls, 15 total] +
            +
          • + +2.89% (49.05%) String#split [15 calls, 18 total] +
          • +
          +
        • +
        • + +2.73% (8.61%) Set#add [15 calls, 15 total] +
        • +
        • + +1.85% (5.85%) String#[] [36 calls, 36 total] +
        • +
        • + +1.70% (5.37%) Object#parse_user [3 calls, 3 total] +
            + +
          +
        • +
        • + +1.37% (4.33%) Class#new [3 calls, 5 total] + +
        • + + +
        +
      • +
      • + +31.25% (32.73%) <Class::IO>#write [1 calls, 1 total] +
      • +
      • + +19.11% (20.02%) <Class::IO>#readlines [1 calls, 1 total] +
      • +
      • + +5.86% (6.14%) <Module::Oj>#dump [1 calls, 1 total] +
      • +
      • + +1.94% (2.04%) Enumerable#sort [1 calls, 1 total] +
          + +
        +
      • +
      • + +1.61% (1.69%) Class#new [1 calls, 5 total] +
          +
        • + +1.17% (72.95%) Set#initialize [1 calls, 1 total] +
            + +
          +
        • +
        +
      • + + + +
      +
    • +
    +
  • + +
+
+ +
+
+ + diff --git a/ruby_prof_reports/callstack7.html b/ruby_prof_reports/callstack7.html new file mode 100644 index 00000000..004c5c85 --- /dev/null +++ b/ruby_prof_reports/callstack7.html @@ -0,0 +1,930 @@ + + + + + ruby-prof call tree + + + + + + + +
+
+ Call tree for application ruby-prof-callstack.rb
Generated on 2023-10-22 04:49:33 +0300 + with options {}
+
+
+ Threshold: + + + + + +
+ + + + +
+ Thread: 80, Fiber: 60 (100.00% ~ 0.0004467619946808554) +
    + +
  • + +100.00% (100.00%) [global]# [1 calls, 1 total] +
      +
    • + +96.22% (96.22%) Object#work [1 calls, 1 total] +
        +
      • + +48.73% (50.65%) Array#each [2 calls, 2 total] +
          +
        • + +30.98% (63.58%) Object#collect_stats_for_user [3 calls, 3 total] +
            +
          • + +18.76% (60.54%) Array#map [21 calls, 36 total] +
              +
            • + +3.71% (19.76%) Array#map [15 calls, 36 total] +
                +
              • + +1.55% (41.92%) String#to_i [45 calls, 60 total] +
              • +
              +
            • +
            • + +3.03% (16.13%) Class#new [15 calls, 17 total] +
                +
              • + +1.45% (47.80%) Date#initialize [15 calls, 15 total] +
              • +
              +
            • +
            • + +2.50% (13.35%) Date#iso8601 [15 calls, 15 total] +
            • +
            • + +1.73% (9.20%) String#split [15 calls, 33 total] +
            • + + +
            +
          • +
          • + +2.80% (9.05%) Array#sort [6 calls, 6 total] +
              +
            • + +1.15% (40.85%) Date#<=> [21 calls, 21 total] +
            • +
            +
          • +
          • + +2.51% (8.10%) Array#any? [3 calls, 3 total] +
              + + +
            +
          • +
          • + +1.19% (3.86%) Array#all? [3 calls, 3 total] +
              + + +
            +
          • + + + + + + +
          +
        • +
        • + +5.13% (10.52%) Object#parse_session [15 calls, 15 total] +
            +
          • + +2.44% (47.68%) String#split [15 calls, 33 total] +
          • +
          +
        • +
        • + +2.71% (5.56%) Set#add [15 calls, 15 total] +
        • +
        • + +1.67% (3.43%) Object#parse_user [3 calls, 3 total] +
            + +
          +
        • + + +
        +
      • +
      • + +22.25% (23.12%) <Class::IO>#write [1 calls, 1 total] +
      • +
      • + +15.31% (15.91%) <Class::IO>#readlines [1 calls, 1 total] +
      • +
      • + +3.44% (3.57%) JSON::Ext::Generator::GeneratorMethods::Hash#to_json [1 calls, 1 total] +
          + +
        +
      • +
      • + +1.73% (1.80%) Enumerable#sort [1 calls, 1 total] +
          + +
        +
      • +
      • + +1.43% (1.49%) Class#new [1 calls, 17 total] +
          +
        • + +1.01% (70.57%) Set#initialize [1 calls, 1 total] +
            + +
          +
        • +
        +
      • + + +
      +
    • +
    +
  • + +
+
+ +
+
+ + diff --git a/ruby_prof_reports/flat1.txt b/ruby_prof_reports/flat1.txt new file mode 100644 index 00000000..9d3b234c --- /dev/null +++ b/ruby_prof_reports/flat1.txt @@ -0,0 +1,55 @@ +Measure Mode: wall_time +Thread ID: 80 +Fiber ID: 60 +Total: 0.000332 +Sort by: self_time + + %self total self wait child calls name location + 23.64 0.000 0.000 0.000 0.000 1 #readlines + 18.54 0.000 0.000 0.000 0.000 10 Array#each + 10.38 0.000 0.000 0.000 0.000 28 Array#map + 7.63 0.000 0.000 0.000 0.000 37 String#split + 4.93 0.000 0.000 0.000 0.000 18 Array#all? + 4.73 0.000 0.000 0.000 0.000 1 [global]# ruby-prof-flat.rb:7 + 3.61 0.000 0.000 0.000 0.000 1 Object#work /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:47 + 3.13 0.000 0.000 0.000 0.000 15 Object#parse_session /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:28 + 2.73 0.000 0.000 0.000 0.000 45 String#upcase + 2.67 0.000 0.000 0.000 0.000 3 Array#select + 2.11 0.000 0.000 0.000 0.000 3 Array#any? + 2.00 0.000 0.000 0.000 0.000 1 Date#initialize + 1.69 0.000 0.000 0.000 0.000 18 Hash#merge + 1.58 0.000 0.000 0.000 0.000 4 Array#sort + 1.48 0.000 0.000 0.000 0.000 30 String#to_i + 1.47 0.000 0.000 0.000 0.000 4 Class#new + 1.41 0.000 0.000 0.000 0.000 4 Array#join + 1.01 0.000 0.000 0.000 0.000 3 Object#parse_user /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:18 + 0.95 0.000 0.000 0.000 0.000 7 Object#collect_stats_from_users /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:39 + 0.77 0.000 0.000 0.000 0.000 3 User#initialize /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:12 + 0.69 0.000 0.000 0.000 0.000 1 Array#uniq + 0.54 0.000 0.000 0.000 0.000 6 Integer#to_s + 0.52 0.000 0.000 0.000 0.000 6 Array#count + 0.50 0.000 0.000 0.000 0.000 6 String#+ + 0.36 0.000 0.000 0.000 0.000 3 Array#max + 0.31 0.000 0.000 0.000 0.000 3 Array#sum + 0.28 0.000 0.000 0.000 0.000 1 Exception#initialize + 0.19 0.000 0.000 0.000 0.000 1 Exception#backtrace + 0.16 0.000 0.000 0.000 0.000 1 Exception#exception + +* recursively called methods + +Columns are: + + %self - The percentage of time spent in this method, derived from self_time/total_time. + total - The time spent in this method and its children. + self - The time spent in this method. + wait - The amount of time this method waited for other threads. + child - The time spent in this method's children. + calls - The number of times this method was called. + name - The name of the method. + location - The location of the method. + +The interpretation of method names is: + + * MyObject#test - An instance method "test" of the class "MyObject" + * #test - The <> characters indicate a method on a singleton class. + diff --git a/ruby_prof_reports/flat2.txt b/ruby_prof_reports/flat2.txt new file mode 100644 index 00000000..239cf082 --- /dev/null +++ b/ruby_prof_reports/flat2.txt @@ -0,0 +1,59 @@ +Measure Mode: wall_time +Thread ID: 80 +Fiber ID: 60 +Total: 0.000585 +Sort by: self_time + + %self total self wait child calls name location + 16.29 0.000 0.000 0.000 0.000 1 #read + 13.71 0.000 0.000 0.000 0.000 1 #write + 13.00 0.000 0.000 0.000 0.000 10 Array#each + 8.04 0.000 0.000 0.000 0.000 35 Array#map + 7.10 0.001 0.000 0.000 0.001 1 Object#work /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:45 + 5.95 0.000 0.000 0.000 0.000 15 #strptime + 5.10 0.000 0.000 0.000 0.000 37 String#split + 2.93 0.000 0.000 0.000 0.000 18 Array#all? + 2.91 0.000 0.000 0.000 0.000 7 Object#collect_stats_from_users /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:37 + 2.88 0.001 0.000 0.000 0.001 1 [global]# ruby-prof-flat.rb:7 + 2.65 0.000 0.000 0.000 0.000 45 String#upcase + 2.47 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 2.45 0.000 0.000 0.000 0.000 15 Date#iso8601 + 1.86 0.000 0.000 0.000 0.000 7 Array#sort + 1.74 0.000 0.000 0.000 0.000 15 Object#parse_session /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:26 + 1.60 0.000 0.000 0.000 0.000 3 Array#select + 1.20 0.000 0.000 0.000 0.000 3 Array#any? + 1.15 0.000 0.000 0.000 0.000 21 Hash#merge + 0.98 0.000 0.000 0.000 0.000 21 Date#<=> + 0.89 0.000 0.000 0.000 0.000 30 String#to_i + 0.89 0.000 0.000 0.000 0.000 4 Array#join + 0.59 0.000 0.000 0.000 0.000 3 Class#new + 0.56 0.000 0.000 0.000 0.000 3 Object#parse_user /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:16 + 0.52 0.000 0.000 0.000 0.000 1 Array#uniq + 0.50 0.000 0.000 0.000 0.000 15 Integer#div + 0.48 0.000 0.000 0.000 0.000 3 User#initialize /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:10 + 0.31 0.000 0.000 0.000 0.000 6 Integer#to_s + 0.29 0.000 0.000 0.000 0.000 6 Array#count + 0.27 0.000 0.000 0.000 0.000 6 String#+ + 0.25 0.000 0.000 0.000 0.000 3 Array#max + 0.19 0.000 0.000 0.000 0.000 3 Array#reverse + 0.17 0.000 0.000 0.000 0.000 3 Array#sum + 0.12 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize + +* recursively called methods + +Columns are: + + %self - The percentage of time spent in this method, derived from self_time/total_time. + total - The time spent in this method and its children. + self - The time spent in this method. + wait - The amount of time this method waited for other threads. + child - The time spent in this method's children. + calls - The number of times this method was called. + name - The name of the method. + location - The location of the method. + +The interpretation of method names is: + + * MyObject#test - An instance method "test" of the class "MyObject" + * #test - The <> characters indicate a method on a singleton class. + diff --git a/ruby_prof_reports/flat3.txt b/ruby_prof_reports/flat3.txt new file mode 100644 index 00000000..67984295 --- /dev/null +++ b/ruby_prof_reports/flat3.txt @@ -0,0 +1,55 @@ +Measure Mode: wall_time +Thread ID: 80 +Fiber ID: 60 +Total: 0.000336 +Sort by: self_time + + %self total self wait child calls name location + 22.72 0.000 0.000 0.000 0.000 1 #readlines + 18.62 0.000 0.000 0.000 0.000 10 Array#each + 10.28 0.000 0.000 0.000 0.000 28 Array#map + 7.73 0.000 0.000 0.000 0.000 37 String#split + 4.83 0.000 0.000 0.000 0.000 18 Array#all? + 4.38 0.000 0.000 0.000 0.000 1 [global]# ruby-prof-flat.rb:7 + 3.48 0.000 0.000 0.000 0.000 1 Object#work /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:47 + 3.14 0.000 0.000 0.000 0.000 1 Date#initialize + 3.13 0.000 0.000 0.000 0.000 15 Object#parse_session /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:28 + 2.86 0.000 0.000 0.000 0.000 45 String#upcase + 2.61 0.000 0.000 0.000 0.000 3 Array#select + 2.09 0.000 0.000 0.000 0.000 3 Array#any? + 1.79 0.000 0.000 0.000 0.000 18 Hash#merge + 1.60 0.000 0.000 0.000 0.000 4 Array#sort + 1.49 0.000 0.000 0.000 0.000 4 Class#new + 1.45 0.000 0.000 0.000 0.000 30 String#to_i + 1.40 0.000 0.000 0.000 0.000 4 Array#join + 1.02 0.000 0.000 0.000 0.000 3 Object#parse_user /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:18 + 0.97 0.000 0.000 0.000 0.000 7 Object#collect_stats_from_users /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:39 + 0.79 0.000 0.000 0.000 0.000 3 User#initialize /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:12 + 0.68 0.000 0.000 0.000 0.000 1 Array#uniq + 0.52 0.000 0.000 0.000 0.000 6 Integer#to_s + 0.52 0.000 0.000 0.000 0.000 6 Array#count + 0.51 0.000 0.000 0.000 0.000 6 String#+ + 0.39 0.000 0.000 0.000 0.000 3 Array#max + 0.34 0.000 0.000 0.000 0.000 3 Array#sum + 0.27 0.000 0.000 0.000 0.000 1 Exception#initialize + 0.23 0.000 0.000 0.000 0.000 1 Exception#backtrace + 0.17 0.000 0.000 0.000 0.000 1 Exception#exception + +* recursively called methods + +Columns are: + + %self - The percentage of time spent in this method, derived from self_time/total_time. + total - The time spent in this method and its children. + self - The time spent in this method. + wait - The amount of time this method waited for other threads. + child - The time spent in this method's children. + calls - The number of times this method was called. + name - The name of the method. + location - The location of the method. + +The interpretation of method names is: + + * MyObject#test - An instance method "test" of the class "MyObject" + * #test - The <> characters indicate a method on a singleton class. + diff --git a/ruby_prof_reports/flat4.txt b/ruby_prof_reports/flat4.txt new file mode 100644 index 00000000..913e900a --- /dev/null +++ b/ruby_prof_reports/flat4.txt @@ -0,0 +1,57 @@ +Measure Mode: wall_time +Thread ID: 80 +Fiber ID: 60 +Total: 0.000511 +Sort by: self_time + + %self total self wait child calls name location + 24.27 0.000 0.000 0.000 0.000 1 #write + 15.30 0.000 0.000 0.000 0.000 1 #readlines + 8.50 0.000 0.000 0.000 0.000 38 *Array#map + 6.45 0.000 0.000 0.000 0.000 51 String#split + 5.73 0.000 0.000 0.000 0.000 4 Array#each + 3.96 0.000 0.000 0.000 0.000 3 Object#collect_all_stats /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb:47 + 3.86 0.000 0.000 0.000 0.000 1 #dump + 3.15 0.000 0.000 0.000 0.000 18 Array#all? + 3.11 0.001 0.000 0.000 0.000 1 [global]# ruby-prof-flat.rb:7 + 2.69 0.000 0.000 0.000 0.000 1 Object#work /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb:67 + 2.25 0.000 0.000 0.000 0.000 18 Class#new + 2.07 0.000 0.000 0.000 0.000 15 Date#initialize + 1.99 0.000 0.000 0.000 0.000 15 Object#parse_session /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb:28 + 1.97 0.000 0.000 0.000 0.000 15 Date#iso8601 + 1.97 0.000 0.000 0.000 0.000 7 Array#sort + 1.90 0.000 0.000 0.000 0.000 60 String#to_i + 1.75 0.000 0.000 0.000 0.000 45 String#upcase + 1.73 0.000 0.000 0.000 0.000 3 Array#select + 1.05 0.000 0.000 0.000 0.000 3 Array#any? + 0.97 0.000 0.000 0.000 0.000 15 String#include? + 0.92 0.000 0.000 0.000 0.000 4 Array#join + 0.91 0.000 0.000 0.000 0.000 21 Date#<=> + 0.63 0.000 0.000 0.000 0.000 3 Hash#merge + 0.59 0.000 0.000 0.000 0.000 3 Object#parse_user /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb:18 + 0.48 0.000 0.000 0.000 0.000 3 User#initialize /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb:12 + 0.42 0.000 0.000 0.000 0.000 1 Array#uniq + 0.34 0.000 0.000 0.000 0.000 6 Integer#to_s + 0.33 0.000 0.000 0.000 0.000 6 Array#count + 0.24 0.000 0.000 0.000 0.000 3 Array#max + 0.24 0.000 0.000 0.000 0.000 3 Array#reverse + 0.23 0.000 0.000 0.000 0.000 3 Array#sum + +* recursively called methods + +Columns are: + + %self - The percentage of time spent in this method, derived from self_time/total_time. + total - The time spent in this method and its children. + self - The time spent in this method. + wait - The amount of time this method waited for other threads. + child - The time spent in this method's children. + calls - The number of times this method was called. + name - The name of the method. + location - The location of the method. + +The interpretation of method names is: + + * MyObject#test - An instance method "test" of the class "MyObject" + * #test - The <> characters indicate a method on a singleton class. + diff --git a/ruby_prof_reports/flat5.txt b/ruby_prof_reports/flat5.txt new file mode 100644 index 00000000..1d8981fa --- /dev/null +++ b/ruby_prof_reports/flat5.txt @@ -0,0 +1,46 @@ +Measure Mode: wall_time +Thread ID: 80 +Fiber ID: 60 +Total: 0.000213 +Sort by: self_time + + %self total self wait child calls name location + 33.31 0.000 0.000 0.000 0.000 1 #readlines + 14.05 0.000 0.000 0.000 0.000 4 Array#each + 11.78 0.000 0.000 0.000 0.000 36 String#split + 6.70 0.000 0.000 0.000 0.000 1 [global]# ruby-prof-flat.rb:7 + 6.46 0.000 0.000 0.000 0.000 15 Array#all? + 4.72 0.000 0.000 0.000 0.000 1 Object#work /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb:49 + 4.67 0.000 0.000 0.000 0.000 15 Object#parse_session /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb:28 + 4.07 0.000 0.000 0.000 0.000 3 Array#select + 2.71 0.000 0.000 0.000 0.000 2 Array#map + 1.56 0.000 0.000 0.000 0.000 1 BasicObject#method_missing + 1.54 0.000 0.000 0.000 0.000 1 Array#sort + 1.49 0.000 0.000 0.000 0.000 3 Object#parse_user /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb:18 + 1.39 0.000 0.000 0.000 0.000 15 String#upcase + 1.36 0.000 0.000 0.000 0.000 3 Class#new + 1.18 0.000 0.000 0.000 0.000 3 User#initialize /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1-refactored.rb:12 + 1.01 0.000 0.000 0.000 0.000 1 Array#uniq + 0.96 0.000 0.000 0.000 0.000 1 Array#join + 0.44 0.000 0.000 0.000 0.000 3 Array#count + 0.38 0.000 0.000 0.000 0.000 1 Exception#backtrace + 0.23 0.000 0.000 0.000 0.000 1 Exception#exception + +* recursively called methods + +Columns are: + + %self - The percentage of time spent in this method, derived from self_time/total_time. + total - The time spent in this method and its children. + self - The time spent in this method. + wait - The amount of time this method waited for other threads. + child - The time spent in this method's children. + calls - The number of times this method was called. + name - The name of the method. + location - The location of the method. + +The interpretation of method names is: + + * MyObject#test - An instance method "test" of the class "MyObject" + * #test - The <> characters indicate a method on a singleton class. + diff --git a/ruby_prof_reports/flat6.txt b/ruby_prof_reports/flat6.txt new file mode 100644 index 00000000..e95ab847 --- /dev/null +++ b/ruby_prof_reports/flat6.txt @@ -0,0 +1,60 @@ +Measure Mode: wall_time +Thread ID: 80 +Fiber ID: 60 +Total: 0.000401 +Sort by: self_time + + %self total self wait child calls name location + 33.28 0.000 0.000 0.000 0.000 1 #write + 17.88 0.000 0.000 0.000 0.000 1 #readlines + 7.83 0.000 0.000 0.000 0.000 3 Array#each + 4.97 0.000 0.000 0.000 0.000 1 #dump + 4.55 0.000 0.000 0.000 0.000 3 Object#collect_all_stats /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:40 + 4.40 0.000 0.000 0.000 0.000 1 [global]# ruby-prof-flat.rb:7 + 4.18 0.000 0.000 0.000 0.000 18 String#split + 3.16 0.000 0.000 0.000 0.000 15 Object#parse_session /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:29 + 3.03 0.000 0.000 0.000 0.000 1 Object#work /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:60 + 2.84 0.000 0.000 0.000 0.000 15 Set#add /home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb:338 + 1.96 0.000 0.000 0.000 0.000 36 String#[] + 1.60 0.000 0.000 0.000 0.000 5 *Class#new + 1.07 0.000 0.000 0.000 0.000 15 String#upcase + 0.95 0.000 0.000 0.000 0.000 3 Object#parse_user /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:19 + 0.90 0.000 0.000 0.000 0.000 1 Enumerable#sort + 0.78 0.000 0.000 0.000 0.000 3 Hash#merge + 0.78 0.000 0.000 0.000 0.000 21 Array#map + 0.74 0.000 0.000 0.000 0.000 4 Array#join + 0.56 0.000 0.000 0.000 0.000 1 Set#initialize /home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb:93 + 0.54 0.000 0.000 0.000 0.000 3 User#initialize /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:13 + 0.52 0.000 0.000 0.000 0.000 1 Set#each /home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb:326 + 0.42 0.000 0.000 0.000 0.000 5 Array#count + 0.39 0.000 0.000 0.000 0.000 6 Array#sort + 0.39 0.000 0.000 0.000 0.000 1 Hash#each_key + 0.29 0.000 0.000 0.000 0.000 3 Array#select + 0.28 0.000 0.000 0.000 0.000 3 Integer#to_s + 0.26 0.000 0.000 0.000 0.000 3 Array#sum + 0.25 0.000 0.000 0.000 0.000 3 Array#max + 0.24 0.000 0.000 0.000 0.000 3 Array#any? + 0.21 0.000 0.000 0.000 0.000 1 Set#size /home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb:151 + 0.21 0.000 0.000 0.000 0.000 3 Array#reverse + 0.19 0.000 0.000 0.000 0.000 3 Array#all? + 0.19 0.000 0.000 0.000 0.000 3 NilClass#to_s + 0.17 0.000 0.000 0.000 0.000 1 Hash#initialize + +* recursively called methods + +Columns are: + + %self - The percentage of time spent in this method, derived from self_time/total_time. + total - The time spent in this method and its children. + self - The time spent in this method. + wait - The amount of time this method waited for other threads. + child - The time spent in this method's children. + calls - The number of times this method was called. + name - The name of the method. + location - The location of the method. + +The interpretation of method names is: + + * MyObject#test - An instance method "test" of the class "MyObject" + * #test - The <> characters indicate a method on a singleton class. + diff --git a/ruby_prof_reports/flat7.txt b/ruby_prof_reports/flat7.txt new file mode 100644 index 00000000..1e7f2671 --- /dev/null +++ b/ruby_prof_reports/flat7.txt @@ -0,0 +1,62 @@ +Measure Mode: wall_time +Thread ID: 80 +Fiber ID: 60 +Total: 0.000472 +Sort by: self_time + + %self total self wait child calls name location + 17.74 0.000 0.000 0.000 0.000 1 #write + 13.78 0.000 0.000 0.000 0.000 1 #readlines + 11.71 0.000 0.000 0.000 0.000 2 Array#each + 8.47 0.000 0.000 0.000 0.000 36 *Array#map + 4.83 0.000 0.000 0.000 0.000 33 String#split + 3.69 0.000 0.000 0.000 0.000 1 [global]# ruby-prof-flat.rb:7 + 3.54 0.000 0.000 0.000 0.000 3 Object#collect_stats_for_user /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:32 + 3.06 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 3.05 0.000 0.000 0.000 0.000 1 Set#size /home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb:151 + 2.96 0.000 0.000 0.000 0.000 15 Date#iso8601 + 2.67 0.000 0.000 0.000 0.000 15 Set#add /home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb:338 + 2.44 0.000 0.000 0.000 0.000 1 Object#work /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:49 + 2.40 0.000 0.000 0.000 0.000 15 Object#parse_session /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:21 + 2.32 0.000 0.000 0.000 0.000 45 String#upcase + 2.25 0.000 0.000 0.000 0.000 17 *Class#new + 2.16 0.000 0.000 0.000 0.000 60 String#to_i + 1.52 0.000 0.000 0.000 0.000 6 Array#sort + 1.39 0.000 0.000 0.000 0.000 15 Date#initialize + 1.18 0.000 0.000 0.000 0.000 3 Array#any? + 1.02 0.000 0.000 0.000 0.000 21 Date#<=> + 1.00 0.000 0.000 0.000 0.000 4 Array#join + 0.98 0.000 0.000 0.000 0.000 15 String#include? + 0.94 0.000 0.000 0.000 0.000 18 String#[] + 0.86 0.000 0.000 0.000 0.000 1 Enumerable#sort + 0.76 0.000 0.000 0.000 0.000 3 Object#parse_user /home/razrush1tel/Programming/ruby/optimization/rails-optimization-task1/task-1.rb:11 + 0.55 0.000 0.000 0.000 0.000 3 Array#all? + 0.41 0.000 0.000 0.000 0.000 1 Set#initialize /home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb:93 + 0.39 0.000 0.000 0.000 0.000 6 Integer#to_s + 0.36 0.000 0.000 0.000 0.000 1 Set#each /home/razrush1tel/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/set.rb:326 + 0.35 0.000 0.000 0.000 0.000 1 Hash#each_key + 0.29 0.000 0.000 0.000 0.000 3 Array#max + 0.22 0.000 0.000 0.000 0.000 3 Array#reverse + 0.22 0.000 0.000 0.000 0.000 3 Array#sum + 0.20 0.000 0.000 0.000 0.000 3 Array#count + 0.16 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize + 0.14 0.000 0.000 0.000 0.000 1 Hash#initialize + +* recursively called methods + +Columns are: + + %self - The percentage of time spent in this method, derived from self_time/total_time. + total - The time spent in this method and its children. + self - The time spent in this method. + wait - The amount of time this method waited for other threads. + child - The time spent in this method's children. + calls - The number of times this method was called. + name - The name of the method. + location - The location of the method. + +The interpretation of method names is: + + * MyObject#test - An instance method "test" of the class "MyObject" + * #test - The <> characters indicate a method on a singleton class. + diff --git a/stackprof-speedscope.rb b/stackprof-speedscope.rb new file mode 100644 index 00000000..be2cfb5b --- /dev/null +++ b/stackprof-speedscope.rb @@ -0,0 +1,9 @@ +require 'json' +require 'stackprof' +require_relative 'task-1' + +profile = StackProf.run(mode: :wall, raw: true) do + work(path: 'data.txt', disable_gc: true) +end + +File.write('stackprof_reports/stackprof.json', JSON.generate(profile)) diff --git a/stackprof.rb b/stackprof.rb new file mode 100644 index 00000000..ea4e1863 --- /dev/null +++ b/stackprof.rb @@ -0,0 +1,6 @@ +require 'stackprof' +require_relative 'task-1' + +StackProf.run(mode: :wall, out: 'stackprof_reports/stackprof.dump', interval: 1000) do + work(path: 'data.txt', disable_gc: true) +end diff --git a/stackprof_reports/stackprof.dump b/stackprof_reports/stackprof.dump new file mode 100644 index 0000000000000000000000000000000000000000..787cdd6607eeae3816b9320fb32f29ba64107620 GIT binary patch literal 109 zcmYkwF$#b%3;@8Q4vH-f{zK3)pOIjr1R9m5=+F=Q3`ZUBsyaKc7e(b`U+Zz0ppnB9 tG&hC-j`u|I!obB-f>o3=kg|bpTjo!_uqyfAIH80d6J`VL8c|5Ic>#B&Bmn>b literal 0 HcmV?d00001 diff --git a/stackprof_reports/stackprof.json b/stackprof_reports/stackprof.json new file mode 100644 index 00000000..64a6e46e --- /dev/null +++ b/stackprof_reports/stackprof.json @@ -0,0 +1 @@ +{"version":1.2,"mode":"wall","interval":1000,"samples":0,"gc_samples":0,"missed_samples":0,"metadata":{},"frames":{}} \ No newline at end of file diff --git a/task-1.rb b/task-1.rb index 778672df..8898189a 100644 --- a/task-1.rb +++ b/task-1.rb @@ -3,56 +3,70 @@ require 'json' require 'pry' require 'date' -require 'minitest/autorun' - -class User - attr_reader :attributes, :sessions - - def initialize(attributes:, sessions:) - @attributes = attributes - @sessions = sessions - end -end +require 'oj' +require 'English' +require 'set' +require 'byebug' def parse_user(user) fields = user.split(',') - parsed_result = { + { 'id' => fields[1], 'first_name' => fields[2], 'last_name' => fields[3], - 'age' => fields[4], + 'age' => fields[4] } end def parse_session(session) fields = session.split(',') - parsed_result = { + { 'user_id' => fields[1], 'session_id' => fields[2], 'browser' => fields[3], 'time' => fields[4], - 'date' => fields[5], + 'date' => fields[5] } end -def collect_stats_from_users(report, users_objects, &block) - users_objects.each do |user| - user_key = "#{user.attributes['first_name']}" + ' ' + "#{user.attributes['last_name']}" - report['usersStats'][user_key] ||= {} - report['usersStats'][user_key] = report['usersStats'][user_key].merge(block.call(user)) - end -end +def collect_stats_for_user(report, user, sessions) + time_sessions = sessions.map { |s| s['time'] }.map(&:to_i) + browsers = sessions.map { |s| s['browser'] } + stats = { + 'sessionsCount' => sessions.count, + 'totalTime' => "#{time_sessions.sum} min.", + 'longestSession' => "#{time_sessions.max} min.", + 'browsers' => browsers.map(&:upcase).sort.join(', '), + 'usedIE' => browsers.any? { |b| b.upcase.include?('INTERNET EXPLORER') }, + 'alwaysUsedChrome' => browsers.all? { |b| b.upcase.include?('CHROME') }, + 'dates' => sessions.map { |s| s['date'] }.map { |d| Date.new(*d.split('-').map(&:to_i)) }.sort.reverse.map(&:iso8601) + } -def work - file_lines = File.read('data.txt').split("\n") + user_key = "#{user['first_name']} #{user['last_name']}" + report['usersStats'][user_key] = stats +end +def work(path: 'data.txt', disable_gc: false) + unique_browsers = Set.new users = [] - sessions = [] - - file_lines.each do |line| - cols = line.split(',') - users = users + [parse_user(line)] if cols[0] == 'user' - sessions = sessions + [parse_session(line)] if cols[0] == 'session' + sessions = {} + current_user = nil + total_users = 0 + total_sessions = 0 + + File.readlines(path, chomp: true).each do |line| + case line[0] + when 'u' + current_user = parse_user(line) + sessions[current_user['id']] = [] + total_users += 1 + users << current_user + when 's' + session = parse_session(line) + total_sessions += 1 + sessions[current_user['id']] << session + unique_browsers.add(session['browser'].upcase) + end end # Отчёт в json @@ -72,105 +86,21 @@ def work report = {} - report[:totalUsers] = users.count + report[:totalUsers] = total_users # Подсчёт количества уникальных браузеров - uniqueBrowsers = [] - sessions.each do |session| - browser = session['browser'] - uniqueBrowsers += [browser] if uniqueBrowsers.all? { |b| b != browser } - end - - report['uniqueBrowsersCount'] = uniqueBrowsers.count - - report['totalSessions'] = sessions.count - report['allBrowsers'] = - sessions - .map { |s| s['browser'] } - .map { |b| b.upcase } - .sort - .uniq - .join(',') + report['uniqueBrowsersCount'] = unique_browsers.size - # Статистика по пользователям - users_objects = [] + report['totalSessions'] = total_sessions - users.each do |user| - attributes = user - user_sessions = sessions.select { |session| session['user_id'] == user['id'] } - user_object = User.new(attributes: attributes, sessions: user_sessions) - users_objects = users_objects + [user_object] - end + report['allBrowsers'] = unique_browsers.sort.join(',') report['usersStats'] = {} - # Собираем количество сессий по пользователям - collect_stats_from_users(report, users_objects) do |user| - { 'sessionsCount' => user.sessions.count } - end - - # Собираем количество времени по пользователям - collect_stats_from_users(report, users_objects) do |user| - { 'totalTime' => user.sessions.map {|s| s['time']}.map {|t| t.to_i}.sum.to_s + ' min.' } - end - - # Выбираем самую длинную сессию пользователя - collect_stats_from_users(report, users_objects) do |user| - { 'longestSession' => user.sessions.map {|s| s['time']}.map {|t| t.to_i}.max.to_s + ' min.' } - end - - # Браузеры пользователя через запятую - collect_stats_from_users(report, users_objects) do |user| - { 'browsers' => user.sessions.map {|s| s['browser']}.map {|b| b.upcase}.sort.join(', ') } - end - - # Хоть раз использовал IE? - collect_stats_from_users(report, users_objects) do |user| - { 'usedIE' => user.sessions.map{|s| s['browser']}.any? { |b| b.upcase =~ /INTERNET EXPLORER/ } } - end - - # Всегда использовал только Chrome? - collect_stats_from_users(report, users_objects) do |user| - { 'alwaysUsedChrome' => user.sessions.map{|s| s['browser']}.all? { |b| b.upcase =~ /CHROME/ } } - end - - # Даты сессий через запятую в обратном порядке в формате iso8601 - collect_stats_from_users(report, users_objects) do |user| - { 'dates' => user.sessions.map{|s| s['date']}.map {|d| Date.parse(d)}.sort.reverse.map { |d| d.iso8601 } } - end - - File.write('result.json', "#{report.to_json}\n") -end - -class TestMe < Minitest::Test - def setup - File.write('result.json', '') - File.write('data.txt', -'user,0,Leida,Cira,0 -session,0,0,Safari 29,87,2016-10-23 -session,0,1,Firefox 12,118,2017-02-27 -session,0,2,Internet Explorer 28,31,2017-03-28 -session,0,3,Internet Explorer 28,109,2016-09-15 -session,0,4,Safari 39,104,2017-09-27 -session,0,5,Internet Explorer 35,6,2016-09-01 -user,1,Palmer,Katrina,65 -session,1,0,Safari 17,12,2016-10-21 -session,1,1,Firefox 32,3,2016-12-20 -session,1,2,Chrome 6,59,2016-11-11 -session,1,3,Internet Explorer 10,28,2017-04-29 -session,1,4,Chrome 13,116,2016-12-28 -user,2,Gregory,Santos,86 -session,2,0,Chrome 35,6,2018-09-21 -session,2,1,Safari 49,85,2017-05-22 -session,2,2,Firefox 47,17,2018-02-02 -session,2,3,Chrome 20,84,2016-11-25 -') + users.each do |user| + collect_stats_for_user(report, user, sessions[user['id']]) end - def test_result - work - expected_result = '{"totalUsers":3,"uniqueBrowsersCount":14,"totalSessions":15,"allBrowsers":"CHROME 13,CHROME 20,CHROME 35,CHROME 6,FIREFOX 12,FIREFOX 32,FIREFOX 47,INTERNET EXPLORER 10,INTERNET EXPLORER 28,INTERNET EXPLORER 35,SAFARI 17,SAFARI 29,SAFARI 39,SAFARI 49","usersStats":{"Leida Cira":{"sessionsCount":6,"totalTime":"455 min.","longestSession":"118 min.","browsers":"FIREFOX 12, INTERNET EXPLORER 28, INTERNET EXPLORER 28, INTERNET EXPLORER 35, SAFARI 29, SAFARI 39","usedIE":true,"alwaysUsedChrome":false,"dates":["2017-09-27","2017-03-28","2017-02-27","2016-10-23","2016-09-15","2016-09-01"]},"Palmer Katrina":{"sessionsCount":5,"totalTime":"218 min.","longestSession":"116 min.","browsers":"CHROME 13, CHROME 6, FIREFOX 32, INTERNET EXPLORER 10, SAFARI 17","usedIE":true,"alwaysUsedChrome":false,"dates":["2017-04-29","2016-12-28","2016-12-20","2016-11-11","2016-10-21"]},"Gregory Santos":{"sessionsCount":4,"totalTime":"192 min.","longestSession":"85 min.","browsers":"CHROME 20, CHROME 35, FIREFOX 47, SAFARI 49","usedIE":false,"alwaysUsedChrome":false,"dates":["2018-09-21","2018-02-02","2017-05-22","2016-11-25"]}}}' + "\n" - assert_equal expected_result, File.read('result.json') - end + File.write('result.json', "#{Oj.dump(report, mode: :compat)}\n") end diff --git a/tests/task-1-spec.rb b/tests/task-1-spec.rb new file mode 100644 index 00000000..46da6e04 --- /dev/null +++ b/tests/task-1-spec.rb @@ -0,0 +1,48 @@ +require 'minitest/autorun' +require 'rspec-benchmark' +require_relative '../task-1' + +RSpec.configure do |config| + config.include RSpec::Benchmark::Matchers +end + +describe 'Task1' do + before do + File.write('result.json', '') + File.write('data.txt', +'user,0,Leida,Cira,0 +session,0,0,Safari 29,87,2016-10-23 +session,0,1,Firefox 12,118,2017-02-27 +session,0,2,Internet Explorer 28,31,2017-03-28 +session,0,3,Internet Explorer 28,109,2016-09-15 +session,0,4,Safari 39,104,2017-09-27 +session,0,5,Internet Explorer 35,6,2016-09-01 +user,1,Palmer,Katrina,65 +session,1,0,Safari 17,12,2016-10-21 +session,1,1,Firefox 32,3,2016-12-20 +session,1,2,Chrome 6,59,2016-11-11 +session,1,3,Internet Explorer 10,28,2017-04-29 +session,1,4,Chrome 13,116,2016-12-28 +user,2,Gregory,Santos,86 +session,2,0,Chrome 35,6,2018-09-21 +session,2,1,Safari 49,85,2017-05-22 +session,2,2,Firefox 47,17,2018-02-02 +session,2,3,Chrome 20,84,2016-11-25 +') + end + + let(:expected_result) { '{"totalUsers":3,"uniqueBrowsersCount":14,"totalSessions":15,"allBrowsers":"CHROME 13,CHROME 20,CHROME 35,CHROME 6,FIREFOX 12,FIREFOX 32,FIREFOX 47,INTERNET EXPLORER 10,INTERNET EXPLORER 28,INTERNET EXPLORER 35,SAFARI 17,SAFARI 29,SAFARI 39,SAFARI 49","usersStats":{"Leida Cira":{"sessionsCount":6,"totalTime":"455 min.","longestSession":"118 min.","browsers":"FIREFOX 12, INTERNET EXPLORER 28, INTERNET EXPLORER 28, INTERNET EXPLORER 35, SAFARI 29, SAFARI 39","usedIE":true,"alwaysUsedChrome":false,"dates":["2017-09-27","2017-03-28","2017-02-27","2016-10-23","2016-09-15","2016-09-01"]},"Palmer Katrina":{"sessionsCount":5,"totalTime":"218 min.","longestSession":"116 min.","browsers":"CHROME 13, CHROME 6, FIREFOX 32, INTERNET EXPLORER 10, SAFARI 17","usedIE":true,"alwaysUsedChrome":false,"dates":["2017-04-29","2016-12-28","2016-12-20","2016-11-11","2016-10-21"]},"Gregory Santos":{"sessionsCount":4,"totalTime":"192 min.","longestSession":"85 min.","browsers":"CHROME 20, CHROME 35, FIREFOX 47, SAFARI 49","usedIE":false,"alwaysUsedChrome":false,"dates":["2018-09-21","2018-02-02","2017-05-22","2016-11-25"]}}}' + "\n" } + + context 'when supplied with small data' do + it 'returns correct result' do + work(path: 'data.txt') + expect(File.read('result.json')).to eq(expected_result) + end + end + + context 'when supplied with large data' do + it 'performs in under 1 minute' do + expect { work(path: 'data_large.txt') }.to perform_under(60).sec + end + end +end