├── lesson ├── test │ ├── test_helper.exs │ └── lesson_test.exs ├── .formatter.exs ├── README.md ├── .gitignore ├── mix.exs ├── lib │ └── lesson.ex └── config │ └── config.exs └── README.md /lesson/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /lesson/.formatter.exs: -------------------------------------------------------------------------------- 1 | # Used by "mix format" 2 | [ 3 | inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] 4 | ] 5 | -------------------------------------------------------------------------------- /lesson/test/lesson_test.exs: -------------------------------------------------------------------------------- 1 | defmodule LessonTest do 2 | use ExUnit.Case 3 | doctest Lesson 4 | 5 | test "greets the world" do 6 | assert Lesson.hello() == :world 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lesson/README.md: -------------------------------------------------------------------------------- 1 | # Lesson 2 | 3 | **TODO: Add description** 4 | 5 | ## Installation 6 | 7 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed 8 | by adding `lesson` to your list of dependencies in `mix.exs`: 9 | 10 | ```elixir 11 | def deps do 12 | [ 13 | {:lesson, "~> 0.1.0"} 14 | ] 15 | end 16 | ``` 17 | 18 | Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) 19 | and published on [HexDocs](https://hexdocs.pm). Once published, the docs can 20 | be found at [https://hexdocs.pm/lesson](https://hexdocs.pm/lesson). 21 | 22 | -------------------------------------------------------------------------------- /lesson/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build/ 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover/ 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps/ 9 | 10 | # Where third-party dependencies like ExDoc output generated docs. 11 | /doc/ 12 | 13 | # Ignore .fetch files in case you like to edit your project deps locally. 14 | /.fetch 15 | 16 | # If the VM crashes, it generates a dump, let's ignore it too. 17 | erl_crash.dump 18 | 19 | # Also ignore archive artifacts (built via "mix archive.build"). 20 | *.ez 21 | 22 | # Ignore package tarball (built via "mix hex.build"). 23 | lesson-*.tar 24 | 25 | -------------------------------------------------------------------------------- /lesson/mix.exs: -------------------------------------------------------------------------------- 1 | defmodule Lesson.MixProject do 2 | use Mix.Project 3 | 4 | def project do 5 | [ 6 | app: :lesson, 7 | version: "0.1.0", 8 | elixir: "~> 1.8", 9 | start_permanent: Mix.env() == :prod, 10 | deps: deps() 11 | ] 12 | end 13 | 14 | # Run "mix help compile.app" to learn about applications. 15 | def application do 16 | [ 17 | extra_applications: [:logger] 18 | ] 19 | end 20 | 21 | # Run "mix help deps" to learn about dependencies. 22 | defp deps do 23 | [ 24 | # {:dep_from_hexpm, "~> 0.3.0"}, 25 | # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} 26 | ] 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ErlangElixirFestHandsOn2019 2 | 3 | ## チャット 4 | 5 | [![Join the chat at https://gitter.im/ErlangElixirFestHandsOn2019/community](https://badges.gitter.im/ErlangElixirFestHandsOn2019/community.svg)](https://gitter.im/ErlangElixirFestHandsOn2019/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 6 | 7 | ハンズオン用にGitterのチャットルームを作成しました。 8 | [こちら](https://gitter.im/ErlangElixirFestHandsOn2019/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link)からjoinしてください。 9 | 10 | 質問等はこちらでおねがいします。 11 | 12 | ## 関連資料 13 | 14 | * [ドキュメント](https://github.com/ohr486/ErlangElixirFestHandsOn2019/wiki) 15 | 16 | ## 進め方 17 | 18 | * ドキュメントのお題を読む 19 | 20 | * ドキュメントの手順通りプログラムを作成・実行する 21 | 22 | * ドキュメントのお題をそれぞれ実行して、プログラムの実行時間を比較する 23 | -------------------------------------------------------------------------------- /lesson/lib/lesson.ex: -------------------------------------------------------------------------------- 1 | defmodule Lesson do 2 | @moduledoc """ 3 | Documentation for Lesson. 4 | """ 5 | 6 | @doc """ 7 | Hello world. 8 | 9 | ## Examples 10 | 11 | iex> Lesson.hello() 12 | :world 13 | 14 | """ 15 | def hello do 16 | :world 17 | end 18 | 19 | # 3-1 20 | def myfunc do 21 | "hello, world." 22 | end 23 | 24 | # 5-2 25 | # nミリ秒以下のランダムな時間sleepさせる 26 | # sleepした時間を返す 27 | def sleep_rand(n) do 28 | sleep_time = :rand.uniform(n) 29 | :timer.sleep(sleep_time) 30 | #IO.puts "#{sleep_time}ミリ秒sleepしました" 31 | sleep_time 32 | end 33 | 34 | # 6-4 35 | # n回、sleep_rand(1000)を繰り返す 36 | def exec_seq(n) do 37 | IO.puts "=== 開始: #{n}回rand_sleepを繰り返す ===" 38 | result = Enum.map(1 .. n, fn(_) -> sleep_rand(1000) end) 39 | IO.puts "=== 終了: #{n}回rand_sleepを繰り返す ===" 40 | result 41 | end 42 | 43 | # 7-4 44 | # n回、sleep_rand(1000)を並列に実行する 45 | def exec_pal(n) do 46 | IO.puts "=== 開始: #{n}回rand_sleepを繰り返す(並列) ===" 47 | list = Enum.map(1..n, fn(_) -> Task.async(Lesson, :sleep_rand, [1000]) end) 48 | result = Enum.map(list, fn(d) -> Task.await(d) end) 49 | IO.puts "=== 終了: #{n}回rand_sleepを繰り返す(並列) ===" 50 | result 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lesson/config/config.exs: -------------------------------------------------------------------------------- 1 | # This file is responsible for configuring your application 2 | # and its dependencies with the aid of the Mix.Config module. 3 | use Mix.Config 4 | 5 | # This configuration is loaded before any dependency and is restricted 6 | # to this project. If another project depends on this project, this 7 | # file won't be loaded nor affect the parent project. For this reason, 8 | # if you want to provide default values for your application for 9 | # third-party users, it should be done in your "mix.exs" file. 10 | 11 | # You can configure your application as: 12 | # 13 | # config :lesson, key: :value 14 | # 15 | # and access this configuration in your application as: 16 | # 17 | # Application.get_env(:lesson, :key) 18 | # 19 | # You can also configure a third-party app: 20 | # 21 | # config :logger, level: :info 22 | # 23 | 24 | # It is also possible to import configuration files, relative to this 25 | # directory. For example, you can emulate configuration per environment 26 | # by uncommenting the line below and defining dev.exs, test.exs and such. 27 | # Configuration from the imported file will override the ones defined 28 | # here (which is why it is important to import them last). 29 | # 30 | # import_config "#{Mix.env()}.exs" 31 | --------------------------------------------------------------------------------