------art_68138_11322615.1185961038442
Content-Type: text/plain; charset=ISO-2022-JP
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

むらけんです.

# 私のところに ruby-dev:31312 が届いてないのが不思議・・・

On 8/1/07, Yukihiro Matsumoto <matz / ruby-lang.org> wrote:
> まつもと ゆきひろです
> ちょうど[ruby-dev:31312]を取り込もうと思っていた矢先だったの
> ですが、どっちがいいですかねえ。

同じ条件で時間を計測して,短い方を採用したらいいと思いました;
で,添付のようなパッチと,ベンチマークプログラムで計測したところ
以下のようになりました.

$ ./ruby -I lib karatsuba.rb
Rehearsal --------------------------------------------------
original         2.410000   0.000000   2.410000 (  9.625259)
ruby-dev:31312   2.420000   0.000000   2.420000 (  9.635740)
ruby-dev:31323   1.740000   0.000000   1.740000 (  6.842046)
----------------------------------------- total: 6.570000sec

                    user     system      total        real
original         2.420000   0.000000   2.420000 (  9.931306)
ruby-dev:31312   2.420000   0.000000   2.420000 (  9.627448)
ruby-dev:31323   1.740000   0.000000   1.740000 (  6.842890)

なぜか ruby-dev:31312 が,オリジナルと比較して早くなってないのですが,
ベンチマークプログラムが悪いのでしょうか・・・
単[ruby-dev:31312] が速くなる条件と,私の [ruby-dev:31323] が
速くなる条件が違うという理解で良いものかどうか.

加えて,[ruby-dev:31323] で添付した私のパッチはバグがある状態のものでした.
正しくは,

+VALUE
+rb_big2str_karatsuba(VALUE x, VALUE base)
+{
+    return rb_big2str0_karatsuba(x, FIX2INT(base), Qtrue);
+}
+

この部分を以下のように気靴討ださい;

崛盲
鰲烽蜃回鰡諱鱇齦矚崛盲 蜴矚黼
   鱚鴈 鰲烽蜃回魄煖癇癆齦矚 矚黼剩鴣紿

あと、Karatsubaといえばかけ算
> の高速ついても(アルゴリズムが理解できず)ほったらかしだっ
> たんですよねえ。

今すぐというわけにはいかないのですが,こちらも手をつけようと思っています.
Ruby にはできるだけ速くなってもらいたいです :)

--
Kenta Murata
OpenPGP FP  A26 35D7 4F98 3498 0810 E0D5 F213 966F E9EB 0BCC

------art_68138_11322615.1185961038442
Content-Type: application/octet-stream; name=bignum_31312_31323.patch
Content-Transfer-Encoding: base64
X-Attachment-Id: f_f4tmk8r8
Content-Disposition: attachment; filename="bignum_31312_31323.patch"

SW5kZXg6IGJpZ251bS5jCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIGJpZ251bS5jCShyZXZpc2lvbiAxMjg1OSkK
KysrIGJpZ251bS5jCSh3b3JraW5nIGNvcHkpCkBAIC0xOSw2ICsxOSw4IEBACiAjaW5jbHVkZSA8
aWVlZWZwLmg+CiAjZW5kaWYKIAorI2luY2x1ZGUgPHN0Lmg+CisKIFZBTFVFIHJiX2NCaWdudW07
CiAKICNpZiBkZWZpbmVkIF9fTUlOR1czMl9fCkBAIC03MjcsMTIgKzcyOSw0NjcgQEAKICAgICBy
ZXR1cm4gc3M7CiB9CiAKKyNkZWZpbmUgTUFYX1BPV0VSX0NBQ0hFX0VOVFJJRVMgNjQKKworc3Ry
dWN0IHBvd2VyX2NhY2hlX2RhdGEKK3sKKyAgICBWQUxVRSBwb3dlcjsKKyAgICBsb25nICBtYWdp
YzsKK307CisKK3N0cnVjdCBwb3dlcl9jYWNoZV9lbnRyeQoreworICAgIHN0X3RhYmxlKiBjYWNo
ZTsKKyAgICBsb25nICAgICAgbGVuOworfTsKKworc3RydWN0IHBvd2VyX2NhY2hlCit7CisgICAg
c3RydWN0IHBvd2VyX2NhY2hlX2VudHJ5IGVudHJpZXNbMzVdOworfTsKKworc3RhdGljIGludAor
bWFya19jYWNoZV9lbnRyeShsb25nIG4xLCBzdHJ1Y3QgcG93ZXJfY2FjaGVfZGF0YSogZGF0YSwg
dm9pZCogXykKK3sKKyAgICByYl9nY19tYXJrKGRhdGEtPnBvd2VyKTsKKyAgICByZXR1cm4gU1Rf
Q09OVElOVUU7Cit9CisKK3N0YXRpYyB2b2lkCitwb3dlcl9jYWNoZV9tYXJrKHN0cnV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1MTI3NTcsIDQuOTA2ODkw
NTk1NjA4NTIsCisgICAgICAgIDQuOTU0MTk2MzEwMzg2ODgsIDUuMCwgICAgICAgICAgICAgIDUu
MDQ0Mzk0MTE5MzU4NDUsCisgICAgICAgIDUuMDg3NDYyODQxMjUwMzQsIDUuMTI5MjgzMDE2OTQ0
OTcsIDUuMTY5OTI1MDAxNDQyMzEKKyAgICB9OworICAgIGxvbmcgYml0czsKKworICAgIGlmIChi
YXNlIDwgMiAmJiAzNiA8IGJhc2UpCisgICAgICByYl9idWcoImlsbGVnYWwgcmFkaXggJWQiLCBi
YXNlKTsKKworICAgIGlmIChGSVhOVU1fUCh4KSkgeworICAgICAgICBiaXRzID0gKFNJWkVPRl9M
T05HKkNIQVJfQklUIC0gMSkvMiArIDE7CisgICAgfQorICAgIGVsc2UgaWYgKEJJR1pFUk9QKHgp
KSB7CisgICAgICAgIHJldHVybiAwOworICAgIH0KKyAgICBlbHNlIHsKKyAgICAgICAgYml0cyA9
IEJJVFNQRVJESUcqUkJJR05VTSh4KS0+bGVuOworICAgIH0KKworICAgIHJldHVybiAobG9uZyko
Yml0cy8oMipsb2dfMltiYXNlIC0gMl0pICsgMSk7Cit9CisKK3N0YXRpYyBsb25nCitiaWcyc3Ry
X2thcmF0c3ViYV93aXRob3V0X3NpZ24oeCwgYmFzZSwgcHRyLCBuMSkKKyAgICBWQUxVRSB4Owor
ICAgIGludCBiYXNlOworICAgIGNoYXIqIHB0cjsKKyAgICBsb25nIG4xOworeworICAgIGxvbmcg
bGVuID0gMipuMTsKKyAgICBWQUxVRSBiLCBxcjsKKworICAgIGlmIChGSVhOVU1fUCh4KSkgewor
ICAgICAgICBWQUxVRSBzdHIgPSByYl9maXgyc3RyKHgsIGJhc2UpOworICAgICAgICBtZW1zZXQo
cHRyLCAnMCcsIGxlbiAtIFJTVFJJTkcoc3RyKS0+bGVuKTsKKyAgICAgICAgTUVNQ1BZKHB0ciAr
IGxlbiAtIFJTVFJJTkcoc3RyKS0+bGVuLCBSU1RSSU5HKHN0ciktPnB0ciwKKyAgICAgICAgICAg
ICAgIGNoYXIsIFJTVFJJTkcoc3RyKS0+bGVuKTsKKyAgICAgICAgcmV0dXJuOworICAgIH0KKyAg
ICBpZiAoQklHWkVST1AoeCkpIHsKKyAgICAgICAgbWVtc2V0KHB0ciwgJzAnLCBsZW4pOworICAg
ICAgICByZXR1cm47CisgICAgfQorCisgICAgaWYgKG4xICUgMiA9PSAxKSArK24xOworICAgIGIg
PSBwb3dlcl9jYWNoZV9nZXRfcG93ZXIoYmFzZSwgbjEpOworICAgIHFyID0gcmJfYmlnX2Rpdm1v
ZCh4LCBiKTsKKyAgICBiaWcyc3RyX2thcmF0c3ViYV93aXRob3V0X3NpZ24oCisgICAgICAgIFJB
UlJBWShxciktPnB0clswXSwgYmFzZSwgcHRyLCAgICAgICAgICAgICAgKGxlbiAtIG4xKS8yKTsK
KyAgICBiaWcyc3RyX2thcmF0c3ViYV93aXRob3V0X3NpZ24oCisgICAgICAgIFJBUlJBWShxcikt
PnB0clsxXSwgYmFzZSwgcHRyICsgKGxlbiAtIG4xKSwgbjEvMik7Cit9CisKIFZBTFVFCityYl9i
aWcyc3RyMF9rYXJhdHN1YmEoeCwgYmFzZSwgdHJpbSkKKyAgICBWQUxVRSB4OworICAgIGludCBi
YXNlOworICAgIGludCB0cmltOworeworICAgIFZBTFVFIHNzLCB4eDsKKyAgICBsb25nIG4xOwor
CisgICAgaWYgKEZJWE5VTV9QKHgpKSB7CisgICAgICAgIHJldHVybiByYl9maXgyc3RyKHgsIGJh
c2UpOworICAgIH0KKyAgICBpZiAoQklHWkVST1AoeCkpIHsKKyAgICAgICAgcmV0dXJuIHJiX3N0
cl9uZXcyKCIwIik7CisgICAgfQorCisgICAgaWYgKGJhc2UgPCAyICYmIDM2IDwgYmFzZSkKKyAg
ICAgICAgcmJfcmFpc2UocmJfZUFyZ0Vycm9yLCAiaWxsZWdhbCByYWRpeCAlZCIsIGJhc2UpOwor
CisgICAgeHggP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0gJ1wwJzsKKworICAgIHJldHVy
biBzczsKK30KKworc3RhdGljIGlubGluZSBpbnQKK2JpZzJzdHJfbm9ybWFsKFZBTFVFIHgsIGxv
bmcgaiwgaW50IGJhc2UsIGludCBoYmFzZSwgY2hhciAqcywgaW50IHRyaW0pCit7CisgICAgbG9u
ZyBpID0gUkJJR05VTSh4KS0+bGVuOworICAgIEJESUdJVCAqZHMgPSBCRElHSVRTKHgpOworCisg
ICAgd2hpbGUgKGkgJiYgaiA+IDEpIHsKKyAgICAgICBsb25nIGsgPSBpOworICAgICAgIEJESUdJ
VF9EQkwgbnVtID0gMDsKKworICAgICAgIHdoaWxlIChrLS0pIHsKKyAgICAgICAgICAgbnVtID0g
QklHVVAobnVtKSArIGRzW2tdOworICAgICAgICAgICBkc1trXSA9IChCRElHSVQpKG51bSAvIGhi
YXNlKTsKKyAgICAgICAgICAgbnVtICU9IGhiYXNlOworICAgICAgIH0KKyAgICAgICBpZiAodHJp
bSAmJiBkc1tpLTFdID09IDApIGktLTsKKyAgICAgICBrID0gU0laRU9GX0JESUdJVFM7CisgICAg
ICAgd2hpbGUgKGstLSkgeworICAgICAgICAgICBzWy0tal0gPSBydWJ5X2RpZ2l0bWFwW251bSAl
IGJhc2VdOworICAgICAgICAgICBudW0gLz0gYmFzZTsKKyAgICAgICAgICAgaWYgKCF0cmltICYm
IGogPCAxKSBicmVhazsKKyAgICAgICAgICAgaWYgKHRyaW0gJiYgaSA9PSAwICYmIG51bSA9PSAw
KSBicmVhazsKKyAgICAgICB9CisgICAgfQorICAgIHJldHVybiBqOworfQorCisjZGVmaW5lIEtB
UkFUU1VCQV9ESUdJVFMgMTAyNAorc3RhdGljIFZBTFVFIGJpZzJzdHJfdGFibGVbMzddWzE2XTsK
Kworc3RhdGljIFZBTFVFIGJpZ3NxcihWQUxVRSB4KTsKK3N0YXRpYyB2b2lkIGJpZ2Rpdm1vZChW
QUxVRSB4LCBWQUxVRSB5LCBWQUxVRSAqZGl2cCwgVkFMVUUgKm1vZHApOworCitzdGF0aWMgaW5s
aW5lIGludAorYmlnMnN0cl9rYXJhdHN1YmFfMzEzMTIoVkFMVUUgeCwgaW50IG4sIGludCBiYXNl
LCBpbnQgaGJhc2UsIGNoYXIgKnMsIGludCB0cmltKQoreworICAgIGxvbmcgaSwgaiwgaywgYnNf
bGVuLCBzaWduID0gUkJJR05VTSh4KS0+c2lnbjsKKyAgICB2b2xhdGlsZSBWQUxVRSB0ID0gYmln
MnN0cl90YWJsZVtiYXNlXVswXSwgdDI7CisgICAgVkFMVUUgKmFzLCAqYnMsIHEsIHI7CisKKyAg
ICBqID0gUkJJR05VTSh0KS0+bGVuOworICAgIGZvciAoaT0wOyBqIDw9IFJCSUdOVU0oeCktPmxl
bjsgaSsrKSBqICo9IDI7CisKKyAgICBhcyA9IEFMTE9DQV9OKFZBTFVFLCBpKTsKKworICAgIGZv
ciAoaT0wLGo9MTsgOyBpKyssaio9MikgeworICAgICAgIGFzW2ldID0gdDsKKyAgICAgICBpZihi
aWcyc3RyX3RhYmxlW2Jhc2VdW2kgKyAxXSkgeworICAgICAgICAgICB0MiA9IGJpZzJzdHJfdGFi
bGVbYmFzZV1baSArIDFdOworICAgICAgIH0KKyAgICAgICBlbHNlIHsKKyAgICAgICAgICAgdDIg
PSBiaWdzcXIodCk7CisgICAgICAgICAgIGlmKGkgKyAxIDwgMTYpIHsKKyAgICAgICAgICAgICAg
IGJpZzJzdHJfdGFibGVbYmFzZV1baSArIDFdID0gdDI7CisgICAgICAgICAgICAgICByYl9nbG9i
YWxfdmFyaWFibGUoJmJpZzJzdHJfdGFibGVbYmFzZV1baSArIDFdKTsKKyAgICAgICAgICAgfQor
ICAgICAgIH0KKyAgICAgICBpZihSQklHTlVNKHgpLT5sZW4gPCBSQklHTlVNKHQyKS0+bGVuKSBi
cmVhazsKKyAgICAgICB0ID0gdDI7CisgICAgfQorCisgICAgYnNfbGVuID0gaiAqIDI7CisgICAg
YnMgPSBBTExPQ0FfTihWQUxVRSwgYnNfbGVuKTsKKyAgICBic1swXSA9IHg7CisgICAgUkJJR05V
TSh4KS0+c2lnbiA9IDE7CisgICAgZm9yICg7IGo+MDsgaS0tLCBqLz0yKSB7CisgICAgICAgZm9y
IChrPTA7IGs8YnNfbGVuOyBrKz1qKjIpIHsKKyAgICAgICAgICAgYmlnZGl2bW9kKGJzW2tdLCBh
c1tpXSwgJnEsICZyKTsKKyAgICAgICAgICAgYnNba10gPSBxOworICAgICAgICAgICBic1trICsg
al0gPSByOworICAgICAgIH0KKyAgICB9CisgICAgUkJJR05VTSh4KS0+c2lnbiA9IHNpZ247CisK
KyAgICBqID0gMDsKKyAgICB3aGlsZShSQklHTlVNKGJzW2pdKS0+bGVuID09IDEgJiYgQkRJR0lU
Uyhic1tqXSlbMF0gPT0gMCkgaisrOworICAgIGZvciAoaT1ic19sZW4tMTsgaT5qOyBpLS0pIHsK
KyAgICAgICBrID0gYmlnMnN0cl9ub3JtYWwoCisgICAgICAgICAgIGJzW2ldLCBLQVJBVFNVQkFf
RElHSVRTLCBiYXNlLCBoYmFzZSwKKyAgICAgICAgICAgcyArIG4gLSBLQVJBVFNVQkFfRElHSVRT
LCBRZmFsc2UpOworICAgICAgIG4gLT0gS0FSQVRTVUJBX0RJR0lUUyAtIGs7CisgICAgfQorICAg
IG4gPSBiaWcyc3RyX25vcm1hbChic1tqXSwgbiwgYmFzZSwgaGJhc2UsIHMsIHRyaW0pOworCisg
ICAgcmV0dXJuIG47Cit9CisKK1ZBTFVFCityYl9iaWcyc3RyMF8zMTMxMihWQUxVRSB4LCBpbnQg
YmFzZSwgaW50IHRyaW0pCit7CisgICAgdm9sYXRpbGUgVkFMVUUgdDsKKyAgICBsb25nIGksIGos
IGhiYXNlOworICAgIFZBTFVFIHNzOworICAgIGNoYXIgKnM7CisKKyAgICBpZiAoRklYTlVNX1Ao
eCkpIHsKKwlyZXR1cm4gcmJfZml4MnN0cih4LCBiYXNlKTsKKyAgICB9CisgICAgaSA9IFJCSUdO
VU0oeCktP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NJWkVPRl9CRElHSVRTID4gMgorICAg
IGhiYXNlICo9IGhiYXNlOworI2VuZGlmCisKKyAgICB0ID0gcmJfYmlnX2Nsb25lKHgpOworICAg
IHNzID0gcmJfc3RyX25ldygwLCBqKzEpOworICAgIHMgPSBSU1RSSU5HKHNzKS0+cHRyOworCisg
ICAgc1swXSA9IFJCSUdOVU0oeCktPnNpZ24gPyAnKycgOiAnLSc7CisgICAgaWYgKFJCSUdOVU0o
eCktPmxlbiA+IFJCSUdOVU0oYmlnMnN0cl90YWJsZVtiYXNlXVswXSktPmxlbiAqIDQpIHsKKyAg
ICAgICBqID0gYmlnMnN0cl9rYXJhdHN1YmFfMzEzMTIodCwgaiwgYmFzZSwgaGJhc2UsIHMsIHRy
aW0pOworICAgIH0KKyAgICBlbHNlIHsKKyAgICAgICBqID0gYmlnMnN0cl9ub3JtYWwodCwgaiwg
YmFzZSwgaGJhc2UsIHMsIHRyaW0pOworICAgIH0KKyAgICBpZiAodHJpbSkge3doaWxlIChzW2pd
ID09ICcwJykgaisrO30KKyAgICBpID0gUlNUUklORyhzcyktPmxlbiAtIGo7CisgICAgaWYgKFJC
SUdOVU0oeCktPnNpZ24pIHsKKwltZW1tb3ZlKHMsIHMraiwgaSk7CisJUlNUUklORyhzcyktPmxl
biA9IGktMTsKKyAgICB9CisgICAgZWxzZSB7CisJbWVtbW92ZShzKzEsIHMraiwgaSk7CisJUlNU
UklORyhzcyktPmxlbiA9IGk7CisgICAgfQorICAgIHNbUlNUUklORyhzcyktPmxlbl0gPSAnXDAn
OworCisgICAgcmV0dXJuIHNzOworfQorCitzdGF0aWMgdm9pZAoraW5pdF9iaWcyc3RyX3RhYmxl
KHZvaWQpCit7CisgICAgaW50IGksIGo7CisgICAgVkFMVUUgdjsKKworICAgIGZvciAoaT0wOyBp
PDM3OyBpKyspIHsKKyAgICAgICB2ID0gcmJfYmlnX3BvdyhyYl9pbnQyYmlnKGkpLCBJTlQyRklY
KEtBUkFUU1VCQV9ESUdJVFMp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iX2RlZmluZV9tZXRob2QocmJfY0JpZ251bSwgImNvZXJjZSIsIHJiX2JpZ19jb2VyY2UsIDEp
OwogICAgIHJiX2RlZmluZV9tZXRob2QocmJfY0JpZ251bSwgIi1AIiwgcmJfYmlnX3VtaW51cywg
MCk7CkBAIC0yMzQ0LDQgKzI4MzMsNiBAQAogICAgIHJiX2RlZmluZV9tZXRob2QocmJfY0JpZ251
bSwgInRvX2YiLCByYl9iaWdfdG9fZiwgMCk7CiAgICAgcmJfZGVmaW5lX21ldGhvZChyYl9jQmln
bnVtLCAiYWJzIiwgcmJfYmlnX2FicywgMCk7CiAgICAgcmJfZGVmaW5lX21ldGhvZChyYl9jQmln
bnVtLCAic2l6ZSIsIHJiX2JpZ19zaXplLCAwKTsKKworICAgIGluaXRfYmlnMnN0cl90YWJsZSgp
OwogfQo------art_68138_11322615.1185961038442
Content-Type: application/octet-stream; name=karatsuba.rb
Content-Transfer-Encoding: base64
X-Attachment-Id: f_f4tmke1h
Content-Disposition: attachment; filename="karatsuba.rb"

cmVxdWlyZSAnYmVuY2htYXJrJwoKJHZhbHVlcyA9ICgxLi4xMDApLnRvX2EuY29sbGVjdHsgcmFu
ZCgxMCoqMTAyNCAtIDEpIH0KCmRlZiBtYWluCiAgJHZhbHVlcy5lYWNoe3x2fCAoMi4uMzYpLmVh
Y2h7fGJ8IHlpZWxkKHYsIGIpIH19CmVuZAoKQmVuY2htYXJrLmJtYm0gZG8gfHh8CiAgeC5yZXBv
cnQoJ29yaWdpbmFsJykgZG8KICAgIG1haW4ge3x2LCBifCB2LnRvX3Nfb3JpZyhiKSB9CiAgZW5k
CiAgeC5yZXBvcnQoJ3J1YnktZGV2OjMxMzEyJykgZG8KICAgIG1haW4ge3x2LCBifCB2LnRvX3Nf
MzEzMTIoYikgfQogIGVuZAogIHgucmVwb3J0KCdydWJ5LWRldjozMTMyMycpIGRvCiAgICBtYWlu
IHt8diwgYnwgdi50b19zKGIpIH0KICBlbmQKZW5kCg------art_68138_11322615.1185961038442--