Commit Graph

27 Commits

Author SHA1 Message Date
Denys Vlasenko
6452c30036 factor: detect squares
If we have a square, the speedup can be extremely large
(in best case example below, it's ~40000 times faster):

$ time ./busybox_old factor 18446743988964486098
18446743988964486098: 2 3037000493 3037000493
real	0m4.246s
$ time ./busybox factor 18446743988964486098
18446743988964486098: 2 3037000493 3037000493
real	0m0.000s

function                                             old     new   delta
isqrt_odd                                              -      57     +57
print_w                                                -      36     +36
factorize                                            218     236     +18
print_h                                                -       7      +7
factorize_numstr                                      65      72      +7
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 2/0 up/down: 125/0)             Total: 125 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-22 20:24:30 +01:00
Denys Vlasenko
901d2c3862 factor: fix typo in undef
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21 07:45:08 +01:00
Denys Vlasenko
3e544d6ec7 factor: code shrink
function                                             old     new   delta
factor_main                                          176     171      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-21 07:22:55 +01:00
Denys Vlasenko
f079f91371 factor: 30% faster trial division (better sieve)
function                                             old     new   delta
packed_wheel                                           -     192    +192
factor_main                                          108     176     +68
factorize                                            284     218     -66
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 260/-66)           Total: 194 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-20 21:37:29 +01:00
Denys Vlasenko
b097a84d62 config: update size information
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-28 03:20:17 +01:00
Denys Vlasenko
72089cf6b4 config: deindent all help texts
Those two spaces after tab have no effect, and always a nuisance when editing.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-21 09:50:55 +02:00
Denys Vlasenko
4eed2c6c50 Update menuconfig items with approximate applet sizes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 22:01:24 +02:00
Denys Vlasenko
d85352b4ff factor: fix stray semicolon
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-17 15:57:07 +02:00
Denys Vlasenko
8352b717ce factor: support "no-argvs" usage
function                                             old     new   delta
factorize_numstr                                       -      72     +72
packed_usage                                       31562   31566      +4
factor_main                                          109     101      -8
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 76/-8)              Total: 68 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-14 14:23:49 +02:00
Denys Vlasenko
107159ef1c factor: improve comments for sieving logic... also fix a typo
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-13 13:38:16 +02:00
Denys Vlasenko
021d50405b factor: improve comments for sieving logic
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-13 13:34:40 +02:00
Denys Vlasenko
c054822027 factor: tweak comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-13 10:51:13 +02:00
Denys Vlasenko
a976aaab0b factor: remove debug code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-11 07:50:42 +02:00
Denys Vlasenko
8a134ec680 libbb: move isqrt from factor, use it in diff too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-11 07:34:56 +02:00
Denys Vlasenko
10673c44f1 factor: much faster, and very slightly larger isqrt()
function                                             old     new   delta
isqrt_odd                                             70      88     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-11 07:02:42 +02:00
Denys Vlasenko
cc1f8ba489 factor: don't be too clever in isqrt - be small instead
function                                             old     new   delta
isqrt_odd                                            111      70     -41

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 18:30:35 +02:00
Denys Vlasenko
ad5394d591 factor: add code to test isqrt() correctness
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 13:53:57 +02:00
Denys Vlasenko
dd3a395053 factor: 25% faster sieving
function                                             old     new   delta
factorize                                            287     260     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 12:10:46 +02:00
Denys Vlasenko
4908c79a01 factor: better comments, slightl more clever conversion even->odd
function                                             old     new   delta
isqrt_odd                                            114     111      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 11:47:48 +02:00
Denys Vlasenko
f428f1dc6c factor: fix HALF_FMT usage
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 10:13:14 +02:00
Denys Vlasenko
12dc4fbf18 factor: fix comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 00:41:11 +02:00
Denys Vlasenko
bef1713217 factor: a bit more simple isqrt
function                                             old     new   delta
isqrt_odd                                             87      80      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 00:28:26 +02:00
Denys Vlasenko
c6476dca54 factor: simpler isqrt
function                                             old     new   delta
isqrt_odd                                            102      87     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 00:24:16 +02:00
Denys Vlasenko
c804d4ec5c factor: factor2 variable is unused now, drop it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-09 23:19:47 +02:00
Denys Vlasenko
7e5f2f3b51 factor: expand comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-09 23:12:38 +02:00
Denys Vlasenko
1d232fd440 factor: 30% faster code (estimate max possible factor just once)
function                                             old     new   delta
factorize                                              -     161    +161
isqrt_odd                                              -     102    +102
factor_main                                          281     110    -171
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/1 up/down: 263/-171)           Total: 92 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-09 22:54:57 +02:00
Denys Vlasenko
ee7f75d94f factor: new applet
thus far only able to factor up to ULLONG_MAX

function                                             old     new   delta
factor_main                                            -     378    +378
packed_usage                                       31427   31502     +75
applet_names                                        2590    2597      +7
applet_main                                         1500    1504      +4
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/0 up/down: 464/0)             Total: 464 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-09 21:18:43 +02:00