Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

homework #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

homework #135

wants to merge 1 commit into from

Conversation

ksilex
Copy link

@ksilex ksilex commented Oct 18, 2023

Где лучше оставлять вопросы, здесь или в teachbase? Пока оставлю тут:
Как поток понимает, что происходит IO операция, и что будет с потоком, когда IO операция завершится? За это ядро ОС отвечает? Где можно подробности работы с потоками и процессами разобрать?

Отчет в https://www.speedscope.app не открылся, ругается на формат, хотя кидаю сгенерированный json

report['usersStats'][user_key] ||= {}
report['usersStats'][user_key] = report['usersStats'][user_key].merge(block.call(user))
def collect_stats_from_users(report, users, &block)
progressbar = ProgressBar.create(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

прогресс-бар кстати может подтормаживать, поэтому при замерах времени (бенчмаркинге) лучше его отключать

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавил ProgressBar уже после всех оптимизаций, просто для пощупать и галочку проставить


report['uniqueBrowsersCount'] = uniqueBrowsers.count
report[:uniqueBrowsersCount] = sessions.uniq { |session| session[:browser] }.size
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Уникальные браузеры удобно в Set / SortedSet собирать

@@ -72,72 +75,40 @@ def work

report = {}

report[:totalUsers] = users.count
report[:totalUsers] = users.size
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

для Array size и count - одно и то же

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot from 2023-10-23 22-28-32
count слегка медленнее

def work(filename: nil, disable_gc: false)
GC.disable if disable_gc
users = fetch_users_and_sessions(filename)
sessions = users.flat_map { |user| user[:sessions] }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не пойму, зачем flat_map

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user[:sessions] массив же, без flat_map надо было бы делать flatten после map

Copy link
Collaborator

@spajic spajic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants