SlideShare ist ein Scribd-Unternehmen logo
1 von 26
ライトニングトーク
自己紹介
twitter: techno_neko
所属:Hokkaido.pm
仕事:組み込み系
テーマ「最適化」
We love optimize!
前回までのあらすじ
カラー画像をモノクロに変換する
perl スクリプトの処理時間を
約 40% まで短縮したところ、
思わぬところからアドバイスと
リクエストを頂いたのであった。
お題
「カラー画像をモノクロに変換」
変換!
モノクロに変換
カラー画像 モノクロ画像
・
・
・
・
・
・
Y = 0.29*R + 0.59*G + 0.11*B
(※係数は、輝度を求める一般的な値)
0x004E4E4E
0x004E4E4E
0x12345678 0x004E4E4E
0x12345678
0x12345678
実行環境
Mac OS X 10.6.4
CPU Intel Core 2 Duo 2.4 GHz
メモリ 4GB 800MHz DDR2 SDRAM
perl 5.12.1
テストデータ
6M pixel ( 3008 x 2000 )
32bit format
モノクロに変換
sub test1 {
# Y = 0.29*R + 0.59*G + 0.11*B
my @factor = ( 0.30, 0.59, 0.11 );
my @argb_test = @argb_src;
for (my $i=0; $i<scalar(@argb_test); $i++) {
my $argb = $argb_test[$i]; # ARGB
my $r = ( ($argb >> 16) & 0xFF );
my $g = ( ($argb >> 8) & 0xFF );
my $b = ( ($argb >> 0) & 0xFF );
my $y = int( ($r * $factor[0]) + ($g * $factor[1]) + ($b * $factor[2]) );
$argb_test[$i] = ( ($y << 16) + ($y << 8) + $y );
}
push @argb_dst, @argb_test;
}
モノクロに変換
TEST1: 24 wallclock secs
(24.00 usr + 0.13 sys =
24.13 CPU) @ 0.04/s (n=1)
これが基準タイム
モノクロに変換 〜 前回の最速
map の中を 1 行にまとめてみた
# Y = 0.29*R + 0.59*G + 0.11*B
my $fr = 0.30 / (1 << 16);
my $fg = 0.59 / (1 << 8);
my $fb = 0.11 / (1 << 0);
my @argb_test = map {
0x010101 * int(
(($_ & 0xFF0000) * $fr)
+ (($_ & 0x00FF00) * $fg)
+ (($_ & 0x0000FF) * $fb)
);
} @argb_src;
モノクロに変換 〜 前回の最速
約 234% 高速化!
TEST7: 11 wallclock secs
(10.04 usr + 0.28 sys =
10.32 CPU) @ 0.10/s (n=1)
TEST1: 24 wallclock secs
(24.00 usr + 0.13 sys =
24.13 CPU) @ 0.04/s (n=1)
use integer;
を手に入れた!
(すべてはここから始まった・・・)
モノクロに変換 〜 その1
use integer;
# Y = 0.29*R + 0.59*G + 0.11*B
my $fr = (30 * 256) / 100;
my $fg = (59 * 256) / 100;
my $fb = 256 - $fr - $fg; #(11 * 256) / 100;
my @argb_test = map {
0x010101 * (
(
( (($_ >> 16) & 0xFF) * $fr )
+ ( (($_ >> 8) & 0xFF) * $fg )
+ ( (($_ >> 0) & 0xFF) * $fb )
) >> 8
);
} @argb_src;
モノクロに変換 〜 その1
約 269% 高速化!
TEST8: 9 wallclock secs
( 8.88 usr + 0.10 sys =
8.98 CPU) @ 0.11/s (n=1)
TEST1: 24 wallclock secs
(24.00 usr + 0.13 sys =
24.13 CPU) @ 0.04/s (n=1)
モノクロに変換 〜 その2
use integer;
# Y = 0.29*R + 0.59*G + 0.11*B
my $fr = (30 * 256) / 100;
my $fg = (59 * 256) / 100;
my $fb = 256 - $fr - $fg; #(11 * 256) / 100;
$fb <<= 8; # only B
my @argb_test = map {
0x010101 * (
(
( (($_ >> 8) & 0xFF00) * $fr )
+ ( ( $_ & 0xFF00) * $fg )
+ ( ( $_ & 0x00FF) * $fb ) # $fb is already "<< 8"
) >> 16
);
} @argb_src;
モノクロに変換 〜 その2
約 317% 削減!
TEST9: 7 wallclock secs
( 7.52 usr + 0.10 sys =
7.62 CPU) @ 0.13/s (n=1)
TEST1: 24 wallclock secs
(24.00 usr + 0.13 sys =
24.13 CPU) @ 0.04/s (n=1)
モノクロに変換 〜 最終章
use integer;
# Y = 0.29*R + 0.59*G + 0.11*B
my $fr = (30 * 128) / 100;
my $fg = (59 * 128) / 100;
my $fb = 128 - $fr - $fg; #(11 * 128) / 100;
$fg <<= 8;
$fb <<= 16;
my @argb_test = map {
0x010101 * (
(
( ( $_ & 0xFF0000) * $fr )
+ ( ( $_ & 0x00FF00) * $fg )
+ ( ( $_ & 0x0000FF) * $fb )
) >> 23 #(24 - 1)
);
} @argb_src;
モノクロに変換 〜 最終章
約 355% 高速化!
TESTA: 7 wallclock secs
( 6.69 usr + 0.11 sys =
6.80 CPU) @ 0.15/s (n=1)
TEST1: 24 wallclock secs
(24.00 usr + 0.13 sys =
24.13 CPU) @ 0.04/s (n=1)
まとめ
まとめ
・最適化とはロマン
まとめ
・最適化とはロマン
・自分との戦い
まとめ
・最適化とはロマン
・自分との戦い
・危険を伴う
故に、
常に問い続けなければ
ならない。
それは・・・、
「そこに愛はあるのかい?」
愛が止まらない ;)
ご清聴、ありがとうございました。

Weitere ähnliche Inhalte

Was ist angesagt?

Wavelet matrix implementation
Wavelet matrix implementationWavelet matrix implementation
Wavelet matrix implementation
MITSUNARI Shigeo
 
条件分岐とcmovとmaxps
条件分岐とcmovとmaxps条件分岐とcmovとmaxps
条件分岐とcmovとmaxps
MITSUNARI Shigeo
 

Was ist angesagt? (20)

Prosym2012
Prosym2012Prosym2012
Prosym2012
 
Effective modern-c++#9
Effective modern-c++#9Effective modern-c++#9
Effective modern-c++#9
 
Rでのtry関数によるエラー処理
Rでのtry関数によるエラー処理Rでのtry関数によるエラー処理
Rでのtry関数によるエラー処理
 
effective modern c++ chapeter36
effective modern c++ chapeter36effective modern c++ chapeter36
effective modern c++ chapeter36
 
Rの高速化
Rの高速化Rの高速化
Rの高速化
 
DTrace for biginners part(2)
DTrace for biginners part(2)DTrace for biginners part(2)
DTrace for biginners part(2)
 
HPC Phys-20201203
HPC Phys-20201203HPC Phys-20201203
HPC Phys-20201203
 
Wavelet matrix implementation
Wavelet matrix implementationWavelet matrix implementation
Wavelet matrix implementation
 
Ssaw08 0701
Ssaw08 0701Ssaw08 0701
Ssaw08 0701
 
Intel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgen
Intel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgenIntel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgen
Intel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgen
 
Async design with Unity3D
Async design with Unity3DAsync design with Unity3D
Async design with Unity3D
 
llvm入門
llvm入門llvm入門
llvm入門
 
C/C++プログラマのための開発ツール
C/C++プログラマのための開発ツールC/C++プログラマのための開発ツール
C/C++プログラマのための開発ツール
 
条件分岐とcmovとmaxps
条件分岐とcmovとmaxps条件分岐とcmovとmaxps
条件分岐とcmovとmaxps
 
デバドラを書いてみよう!
デバドラを書いてみよう!デバドラを書いてみよう!
デバドラを書いてみよう!
 
Intro to SVE 富岳のA64FXを触ってみた
Intro to SVE 富岳のA64FXを触ってみたIntro to SVE 富岳のA64FXを触ってみた
Intro to SVE 富岳のA64FXを触ってみた
 
emcjp Item 42
emcjp Item 42emcjp Item 42
emcjp Item 42
 
Effective Modern C++ 読書会 Item 35
Effective Modern C++ 読書会 Item 35Effective Modern C++ 読書会 Item 35
Effective Modern C++ 読書会 Item 35
 
LLVM最適化のこつ
LLVM最適化のこつLLVM最適化のこつ
LLVM最適化のこつ
 
マーク&スイープ勉強会
マーク&スイープ勉強会マーク&スイープ勉強会
マーク&スイープ勉強会
 

Andere mochten auch

Emerging technologies in_adult_education_classroombl (2)
Emerging technologies in_adult_education_classroombl (2)Emerging technologies in_adult_education_classroombl (2)
Emerging technologies in_adult_education_classroombl (2)
Nell Eckersley
 
NGN Company Profile November08
NGN Company Profile November08NGN Company Profile November08
NGN Company Profile November08
Serdar Salepcioglu
 
Future of Composite Apps S-Controls and Beyond
Future of Composite Apps S-Controls and BeyondFuture of Composite Apps S-Controls and Beyond
Future of Composite Apps S-Controls and Beyond
dreamforce2006
 
Data table for falling steel
Data table for falling steelData table for falling steel
Data table for falling steel
Ciyyu Kudu
 
China placi de circuit imprimat preţul de listă
China placi de circuit imprimat preţul de listăChina placi de circuit imprimat preţul de listă
China placi de circuit imprimat preţul de listă
grace cheng
 

Andere mochten auch (16)

RIMS Update - Best Practices for Roading Asset Managemment
RIMS Update - Best Practices for Roading Asset ManagemmentRIMS Update - Best Practices for Roading Asset Managemment
RIMS Update - Best Practices for Roading Asset Managemment
 
Google Science Fair Summary
Google Science Fair SummaryGoogle Science Fair Summary
Google Science Fair Summary
 
Creating Email Campaigns that Work: A Focus on Design Elements
Creating Email Campaigns that Work: A Focus on Design ElementsCreating Email Campaigns that Work: A Focus on Design Elements
Creating Email Campaigns that Work: A Focus on Design Elements
 
November 12 : (Education)
November 12 : (Education)November 12 : (Education)
November 12 : (Education)
 
SharePoint Saturday Houston: SharePoint 2010 Performance
SharePoint Saturday Houston: SharePoint 2010 PerformanceSharePoint Saturday Houston: SharePoint 2010 Performance
SharePoint Saturday Houston: SharePoint 2010 Performance
 
Emerging technologies in_adult_education_classroombl (2)
Emerging technologies in_adult_education_classroombl (2)Emerging technologies in_adult_education_classroombl (2)
Emerging technologies in_adult_education_classroombl (2)
 
Ppt ch12 marien_4_e-205401
Ppt ch12 marien_4_e-205401Ppt ch12 marien_4_e-205401
Ppt ch12 marien_4_e-205401
 
Mis deberes y derechos como aprendiz sena
Mis deberes y derechos como aprendiz senaMis deberes y derechos como aprendiz sena
Mis deberes y derechos como aprendiz sena
 
NGN Company Profile November08
NGN Company Profile November08NGN Company Profile November08
NGN Company Profile November08
 
Catálogo xpress - Equinos
Catálogo xpress - EquinosCatálogo xpress - Equinos
Catálogo xpress - Equinos
 
Microfiber goods
Microfiber goods Microfiber goods
Microfiber goods
 
UIMP: Sistema Multiagente CBR para Turismo de Salamanca
UIMP: Sistema Multiagente CBR para Turismo de SalamancaUIMP: Sistema Multiagente CBR para Turismo de Salamanca
UIMP: Sistema Multiagente CBR para Turismo de Salamanca
 
Future of Composite Apps S-Controls and Beyond
Future of Composite Apps S-Controls and BeyondFuture of Composite Apps S-Controls and Beyond
Future of Composite Apps S-Controls and Beyond
 
Data table for falling steel
Data table for falling steelData table for falling steel
Data table for falling steel
 
Taller de autoestima. gestalt branden
Taller de autoestima. gestalt brandenTaller de autoestima. gestalt branden
Taller de autoestima. gestalt branden
 
China placi de circuit imprimat preţul de listă
China placi de circuit imprimat preţul de listăChina placi de circuit imprimat preţul de listă
China placi de circuit imprimat preţul de listă
 

Ähnlich wie テーマ「最適化 その2」

Rのデータ構造とメモリ管理
Rのデータ構造とメモリ管理Rのデータ構造とメモリ管理
Rのデータ構造とメモリ管理
Takeshi Arabiki
 
LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)
LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)
LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)
Takeshi Yamamuro
 
Maatkit で MySQL チューニング
Maatkit で MySQL チューニングMaatkit で MySQL チューニング
Maatkit で MySQL チューニング
Kensuke Nagae
 

Ähnlich wie テーマ「最適化 その2」 (20)

x86とコンテキストスイッチ
x86とコンテキストスイッチx86とコンテキストスイッチ
x86とコンテキストスイッチ
 
並列対決 Elixir × Go × C# x Scala , Node.js
並列対決 Elixir × Go × C# x Scala , Node.js並列対決 Elixir × Go × C# x Scala , Node.js
並列対決 Elixir × Go × C# x Scala , Node.js
 
Slide
SlideSlide
Slide
 
Fftw誰得ガイド
Fftw誰得ガイドFftw誰得ガイド
Fftw誰得ガイド
 
Bluespec @waseda(PDF)
Bluespec @waseda(PDF)Bluespec @waseda(PDF)
Bluespec @waseda(PDF)
 
Spmv9forpublic
Spmv9forpublicSpmv9forpublic
Spmv9forpublic
 
Rのデータ構造とメモリ管理
Rのデータ構造とメモリ管理Rのデータ構造とメモリ管理
Rのデータ構造とメモリ管理
 
0x300
0x3000x300
0x300
 
LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)
LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)
LLVMで遊ぶ(整数圧縮とか、x86向けの自動ベクトル化とか)
 
フラグを愛でる
フラグを愛でるフラグを愛でる
フラグを愛でる
 
Halide による画像処理プログラミング入門
Halide による画像処理プログラミング入門Halide による画像処理プログラミング入門
Halide による画像処理プログラミング入門
 
Clojure programming-chapter-2
Clojure programming-chapter-2Clojure programming-chapter-2
Clojure programming-chapter-2
 
ラズパイでデバイスドライバを作ってみた。
ラズパイでデバイスドライバを作ってみた。ラズパイでデバイスドライバを作ってみた。
ラズパイでデバイスドライバを作ってみた。
 
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
 
文献紹介:SegFormer: Simple and Efficient Design for Semantic Segmentation with Tr...
文献紹介:SegFormer: Simple and Efficient Design for Semantic Segmentation with Tr...文献紹介:SegFormer: Simple and Efficient Design for Semantic Segmentation with Tr...
文献紹介:SegFormer: Simple and Efficient Design for Semantic Segmentation with Tr...
 
これからのコンピューティングとJava(Hacker Tackle)
これからのコンピューティングとJava(Hacker Tackle)これからのコンピューティングとJava(Hacker Tackle)
これからのコンピューティングとJava(Hacker Tackle)
 
Altanative macro
Altanative macroAltanative macro
Altanative macro
 
Maatkit で MySQL チューニング
Maatkit で MySQL チューニングMaatkit で MySQL チューニング
Maatkit で MySQL チューニング
 
Material
MaterialMaterial
Material
 
X hago2 shortcoding 20110827
X hago2 shortcoding 20110827X hago2 shortcoding 20110827
X hago2 shortcoding 20110827
 

Mehr von technocat (7)

GUIアプリに必要な3つのこと
GUIアプリに必要な3つのことGUIアプリに必要な3つのこと
GUIアプリに必要な3つのこと
 
perl meets beats.
perl meets beats.perl meets beats.
perl meets beats.
 
画像を縮小するお話
画像を縮小するお話画像を縮小するお話
画像を縮小するお話
 
テーマ「perl meets beats」
テーマ「perl meets beats」テーマ「perl meets beats」
テーマ「perl meets beats」
 
記念撮影で気を付けるべき 4 つのこと
記念撮影で気を付けるべき 4 つのこと記念撮影で気を付けるべき 4 つのこと
記念撮影で気を付けるべき 4 つのこと
 
テーマ「なんでもないようなこと」
テーマ「なんでもないようなこと」テーマ「なんでもないようなこと」
テーマ「なんでもないようなこと」
 
テーマ「Hokkaido.pmからのお知らせ」
テーマ「Hokkaido.pmからのお知らせ」テーマ「Hokkaido.pmからのお知らせ」
テーマ「Hokkaido.pmからのお知らせ」
 

テーマ「最適化 その2」