Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Go言語の紹介(かなり浅く浅く)(仮)(お盆開け勉強会)
Search
Symptote
August 25, 2014
Programming
210
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Go言語の紹介(かなり浅く浅く)(仮)(お盆開け勉強会)
Symptote
August 25, 2014
Other Decks in Programming
See All in Programming
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
150
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.3k
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
130
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
330
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
590
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.6k
AWSに止められる覚悟してますか?
morizo_1984
2
500
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
670
wkhtmltopdfの次どうするか問題2026
willnet
2
1.8k
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
330
Are APIs Still Relevant in the AI Era?
soyuka
0
400
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
330
Featured
See All Featured
Facilitating Awesome Meetings
lara
57
7.2k
New Earth Scene 8
popppiees
4
2.6k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Typedesign – Prime Four
hannesfritz
42
3.2k
WCS-LA-2024
lcolladotor
0
840
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Skip the Path - Find Your Career Trail
mkilby
1
240
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
330
Why Our Code Smells
bkeepers
PRO
340
58k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Designing for Timeless Needs
cassininazir
1
510
Transcript
Goݴޠͷհʢ͔ͳΓઙ͘ઙ͘ʣ(Ծ) @a0symptote
ࣗݾհ ໊લ : ͠Μͬͱ ྸ : 20 ॴଐ : ߴઐ
ڵຯ : ɹ ɹֶͰ͏ਤ(άϥϑ)ͷ࡞
ຊͷ༰
Goݴޠͬͯʁ Google ͕։ൃͯ͠Δݴޠ γϯϓϧͳߏจͰ͕͍ͷ͕ಛ ฒྻॲཧʹڧ͘ɼ؆୯ʹ࣮ग़དྷΔ webΞϓϦέʔγϣϯΛ࡞ΔͨΊͷϥΠϒϥϦ͕Ұഋ ࣈ۟ɾߏจղੳ༻ͷϥΠϒϥϦҰഋ Ϛείοτ͕ՄѪ͍ʂʂʂʂʂʂʂʂʂʂʂʂʂ ࢀߟจݙ :
http:/ /golang.jp
Կʹ͑Δʁ WebΞϓϦέʔγϣϯͷ࡞ ΠϯλϓϦλɾίϯύΠϥͷ։ൃ ܭࢉ etc…
Կʹ͑Δʁ WebΞϓϦέʔγϣϯͷ࡞ ΠϯλϓϦλɾίϯύΠϥͷ։ൃ ܭࢉ etc… ͋ Ε ɼ ଞ ͷ
ݴ ޠ Ͱ ྑ ͘ ͳ ͍……ʁ
͔֬ʹ
GoݴޠΛ͏ཧ༝ͬͯʁ Goݴޠ͕͖Ͱ͖Ͱͨ·Βͳ͍ ָʹฒྻॲཧΛར༻͍ͨ͠
GoݴޠΛ͏ཧ༝ͬͯʁ Goݴޠ͕͖Ͱ͖Ͱͨ·Βͳ͍ ָʹฒྻॲཧΛར༻͍ͨ͠ ී௨ͬͪ͜ʁ
GoݴޠΛ͏ཧ༝ͬͯʁ Goݴޠ͕͖Ͱ͖Ͱͨ·Βͳ͍ ָʹฒྻॲཧΛར༻͍ͨ͠ ී௨ͬͪ͜ʁ ͱ ͍ ͏ Θ ͚ Ͱ
GoݴޠʹΑΔָʑฒྻॲཧ @a0symptote
ָʹฒྻॲཧ͢ΔͨΊ͚ͩʹ GoݴޠΛ͏ͷͪΐͬͱ……
ղܾࡦ
ղܾࡦ ଞͷݴޠͰॻ͍ͨιʔεΛ GoݴޠͰऔΓࠐΜͰ͓͏
औΓࠐΉͨΊͷํ๏
औΓࠐΉͨΊͷํ๏ cgoͱ͍͏πʔϧ͕Goݴޠʹ༻ҙ͞Ε͍ͯΔ
औΓࠐΉͨΊͷํ๏ cgoͱ͍͏πʔϧ͕Goݴޠʹ༻ҙ͞Ε͍ͯΔ ͓ΘΓ
͕͢͞ʹຯؾͳ͍ͷͰ…… ͲΜͳݴޠ͕͑·͔͢ʁ Question C/C++ Ada Fortran Java Objective-C/C++ Answer
͕͢͞ʹຯؾͳ͍ͷͰ…… ͲΜͳݴޠ͕͑·͔͢ʁ Question C/C++ Ada Fortran Java Objective-C/C++ Answer gccͰίϯύΠϧग़དྷΔݴޠͳΒԿͰ
࣮ࡍͷιʔεݟͯΈΑ͏ package main ! /* ! #include<math.h> int larger(int a,
int b){return (a > b) ? a : b;} ! */ ! import "C" import "fmt" ! func main() { fmt.Println(C.larger(1, 2)) fmt.Println(C.cos(30.0 * 3.14 / 180.0)) }
࣮ࡍͷιʔεݟͯΈΑ͏ package main ! /* ! #include<math.h> int larger(int a,
int b){return (a > b) ? a : b;} ! */ ! import "C" import "fmt" ! func main() { fmt.Println(C.larger(1, 2)) fmt.Println(C.cos(30.0 * 3.14 / 180.0)) } ͜ͷίϝϯτͷதʹ Cݴޠͷιʔε
࣮ࡍͷιʔεݟͯΈΑ͏ package main ! /* ! #include<math.h> int larger(int a,
int b){return (a > b) ? a : b;} ! */ ! import "C" import "fmt" ! func main() { fmt.Println(C.larger(1, 2)) fmt.Println(C.cos(30.0 * 3.14 / 180.0)) } ͜ͷίϝϯτͷதʹ Cݴޠͷιʔε ͜ͷΑ͏ʹGoݴޠͷ Ұ෦ͱͯ͠ݺͼग़ͤΔɽ
࣮ࡍͷιʔεݟͯΈΑ͏ package main ! /* ! #include<math.h> int larger(int a,
int b){return (a > b) ? a : b;} ! */ ! import "C" import "fmt" ! func main() { fmt.Println(C.larger(1, 2)) fmt.Println(C.cos(30.0 * 3.14 / 180.0)) } ͜ͷίϝϯτͷதʹ Cݴޠͷιʔε ͜ͷΑ͏ʹGoݴޠͷ Ұ෦ͱͯ͠ݺͼग़ͤΔɽ ϥΠϒϥϦݺΔ
CݴޠҎ֎Ͱʁ package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:
-framework Foundation z#import <Foundation/Foundation.h> #import <objc/Object.h> void fizzBuzz(int n) { for(int i = 1; i <= n; ++i) if(i % 15 == 0) NSLog(@"fizzbuzz\n"); else if(i % 5 == 0) NSLog(@"buzz\n"); else if(i % 3 == 0) NSLog(@"fizz\n"); else NSLog(@"%d\n", i); } */ import "C" ! func main() { C.fizzBuzz(20) }
CݴޠҎ֎Ͱʁ package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:
-framework Foundation z#import <Foundation/Foundation.h> #import <objc/Object.h> void fizzBuzz(int n) { for(int i = 1; i <= n; ++i) if(i % 15 == 0) NSLog(@"fizzbuzz\n"); else if(i % 5 == 0) NSLog(@"buzz\n"); else if(i % 3 == 0) NSLog(@"fizz\n"); else NSLog(@"%d\n", i); } */ import "C" ! func main() { C.fizzBuzz(20) }
CݴޠҎ֎Ͱʁ package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:
-framework Foundation z#import <Foundation/Foundation.h> #import <objc/Object.h> void fizzBuzz(int n) { for(int i = 1; i <= n; ++i) if(i % 15 == 0) NSLog(@"fizzbuzz\n"); else if(i % 5 == 0) NSLog(@"buzz\n"); else if(i % 3 == 0) NSLog(@"fizz\n"); else NSLog(@"%d\n", i); } */ import "C" ! func main() { C.fizzBuzz(20) } gccʹೖ͍ͬͯΕɼCFLAGS͔Β ࢦఆͯ͠Εͳ͘։͚Δ
CݴޠҎ֎Ͱʁ package main /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS:
-framework Foundation z#import <Foundation/Foundation.h> #import <objc/Object.h> void fizzBuzz(int n) { for(int i = 1; i <= n; ++i) if(i % 15 == 0) NSLog(@"fizzbuzz\n"); else if(i % 5 == 0) NSLog(@"buzz\n"); else if(i % 3 == 0) NSLog(@"fizz\n"); else NSLog(@"%d\n", i); } */ import "C" ! func main() { C.fizzBuzz(20) } gccʹೖ͍ͬͯΕɼCFLAGS͔Β ࢦఆͯ͠Εͳ͘։͚Δ ϩʔυ͍ͨ͠ϥΠϒϥϦಉ͡ ͘LDFLAGSͰࢦఆग़དྷΔ
ͦ͏ݴ͑ฒྻॲཧʁ
ͦ͏ݴ͑ฒྻॲཧʁ go 並列化したい関数()
ͦ͏ݴ͑ฒྻॲཧʁ go 並列化したい関数() ͓ΘΓ
ࠓճฒྻͰॲཧͯ͠ΈΔ ԁपπΛٻΊΑ Question
ղ͖ํ π = Arctan 0.25. ্ࣜʹ͍ͭͯɼࠨลΛTaylorల։͢Δͱ π = Σ{0.25n /
(2n + 1)}. Answer ࢀߟจݙ : wikipedia-ԁपͷྺ࢙
ղ͖ํ π = Arctan 0.25. ্ࣜʹ͍ͭͯɼࠨลΛTaylorల։͢Δͱ π = Σ{0.25n /
(2n + 1)}. Answer ࢀߟจݙ : wikipedia-ԁपͷྺ࢙ ඍੵͱ͔͔Βͳ͍ΜͰɼ࣮ݧతʹٻΊ·͢
1ลͷ͕͞1ͷਖ਼ํܗͱͦͷԁΛ ߟ͑Δɽਖ਼ํܗʹదʹΛ͏ͪ ԁʹೖ͍ͬͯΔͱͦΕҎ֎ͷͷൺΛ ٻΊΔɽ ࣮ݧతʹʁ Answer CݴޠɿγϛϡϨʔτ Goݴޠɿฒྻॲཧ
۩ମྫ package main ! /* #include <stdio.h> #include <stdlib.h> #include
<time.h> void init(){srand(time(NULL));} double pi(){ //正方形と円の比を計算する,省略 } */ import "C" import "fmt" import "runtime" ! func main() { const NCPU = 5 runtime.GOMAXPROCS(NCPU) ! const MAX = 360000 / NCPU ch := make(chan float64, NCPU) ! C.init() ! for i := 0; i < NCPU; i++ { go func() { for j := 0; j < MAX; j++ { ch <- float64(C.pi()) } }() } ! p := 0.0 for i := 0; i < MAX*NCPU; i++ { p = <-ch + p } ! fmt.Println("円周率π ≈", p/(MAX*NCPU)) }
۩ମྫ package main ! /* #include <stdio.h> #include <stdlib.h> #include
<time.h> void init(){srand(time(NULL));} double pi(){ //正方形と円の比を計算する,省略 } */ import "C" import "fmt" import "runtime" ! func main() { const NCPU = 5 runtime.GOMAXPROCS(NCPU) ! const MAX = 360000 / NCPU ch := make(chan float64, NCPU) ! C.init() ! for i := 0; i < NCPU; i++ { go func() { for j := 0; j < MAX; j++ { ch <- float64(C.pi()) } }() } ! p := 0.0 for i := 0; i < MAX*NCPU; i++ { p = <-ch + p } ! fmt.Println("円周率π ≈", p/(MAX*NCPU)) } ϓϩηεͷઃఆ
۩ମྫ package main ! /* #include <stdio.h> #include <stdlib.h> #include
<time.h> void init(){srand(time(NULL));} double pi(){ //正方形と円の比を計算する,省略 } */ import "C" import "fmt" import "runtime" ! func main() { const NCPU = 5 runtime.GOMAXPROCS(NCPU) ! const MAX = 360000 / NCPU ch := make(chan float64, NCPU) ! C.init() ! for i := 0; i < NCPU; i++ { go func() { for j := 0; j < MAX; j++ { ch <- float64(C.pi()) } }() } ! p := 0.0 for i := 0; i < MAX*NCPU; i++ { p = <-ch + p } ! fmt.Println("円周率π ≈", p/(MAX*NCPU)) } ϓϩηεͷઃఆ ฒྻॲཧ෦(ແ໊ؔ)
࣮ߦͷ࣌ؒͷධՁ 1ίΞͰ࣮ߦ 5ίΞͰ࣮ߦ ࣮ߦ࣌ؒ 1m2.151s 0m45.90s
࣮ߦͷ࣌ؒͷධՁ 1ίΞͰ࣮ߦ 5ίΞͰ࣮ߦ ࣮ߦ࣌ؒ 1m2.151s 0m45.90s 1/3ͷ࣮ߦ࣌ؒͷݮʹ
ࠓճͷ·ͱΊ Goݴޠɼ͍ͬ͢͝Մೳੑʹ͋;ΕͯΔ ଞͷݴޠͷྑ͍ॴΛͭ·Έ৯͍ͯ͠ར༻Ͱ͖Δ Goݴޠࣗମ؆୯ʹฒྻॲཧ͕ग़དྷͨΓͱɼதʑݟॴ͕͋Δ ͜Ε͔Βൃల͍ͯ͘͠ͷͰɼظͯͬͯͯ͠Լ͍͞
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠