Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39603
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Cecil Westerhof <Cecil@decebal.nl> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Compare generics (that are numbers) |
| Date | Thu, 30 Jul 2020 17:00:11 +0200 |
| Organization | Decebal Computing |
| Lines | 48 |
| Message-ID | <87mu3h59qc.fsf@munus.decebal.nl> (permalink) |
| References | <87k0ym73id.fsf@munus.decebal.nl> <rfscpe$doa$1@dont-email.me> <87ft9a6u35.fsf@munus.decebal.nl> <rfsgek$jm4$1@gioia.aioe.org> <87bljy6qu3.fsf@munus.decebal.nl> <rft7um$17k2$1@gioia.aioe.org> <87zh7h5ouj.fsf@munus.decebal.nl> <rfugel$qk$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | reader02.eternal-september.org; posting-host="f8d0a939acc3a275654d8d40652c9997"; logging-data="19226"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1971CsbUpDKTPp2/3SS9dCGG74/SUvArZ8=" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
| Cancel-Lock | sha1:/q4oiJUBQeAD/s+qVvZ5pPlM1kc= sha1:jGJWRNhZCE8w7rklz6yMY+joeuE= |
| Xref | csiph.com comp.lang.java.programmer:39603 |
Show key headers only | View raw
Eric Sosman <esosman@comcast-dot-net.invalid> writes: > On 7/30/2020 5:33 AM, Cecil Westerhof wrote: >> Arne Vajhøj <arne@vajhoej.dk> writes: >> >>> But if this is performance critical then why not just drop the >>> generic stuff and write specific code for the types? >> >> Because I want to show the differences between using >> Float/float/Integer/int and different implementations thereof. > > Is this a "practical problem," or a "teaching exercise?" If the > former, I'd be interested to know how it arises -- needing to compare > one arbitrary Number to another (BigDecimal vs. AtomicLong?) seems not > out of the question, but surely unusual. Lets lift a corner of the veil. ;-) It is in between. During a whiteboard session during a job interview I was asked to optimise something. It started with going from Float to Integer. (In this case that was possible.) The functionality of Integer was not used, so it was good to switch to int. But a further optimisation would be to use an int array. When back home I was curious and started implementing it. For readability I also tried int[number][2], but that did not work at all. I kept it in my program, because it is good to show the result in my opinion. Then I also tried int[2][number]. With 25 million records and 250 repeats I got: |-----------------------+--------+----------+---------+---------+---------+----------+----------+----------| | Type | Memory | Sys Time | Gen Min | Gen Max | Gen Avg | Calc Min | Calc Max | Calc Avg | |-----------------------+--------+----------+---------+---------+---------+----------+----------+----------| | Integer Class[number] | 3.8 GB | 34.0 | 5.33E3 | 1.11E4 | 7.65E3 | 367 | 656 | 447.60 | | int Class[number] | 2.3 GB | 15.5 | 2.53E3 | 4.64E3 | 3.44E3 | 202 | 340 | 267.40 | | int [2 * number] | 0.6 GB | 5.5 | 1.09E3 | 1.52E3 | 1.27E3 | 61 | 112 | 75.10 | | int [number][2] | 2.3 GB | 24.0 | 4.23E3 | 7.30E3 | 5.51E3 | 183 | 338 | 239.18 | | int [2][number] | 0.6 GB | 6.0 | 1.06E3 | 1.61E3 | 1.30E3 | 81 | 133 | 107.03 | |-----------------------+--------+----------+---------+---------+---------+----------+----------+----------| System time is in minutes. Other times in milliseconds. With Floats the savings on memory will be a lot less, because the overhead for objects is less. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Compare generics (that are numbers) Cecil Westerhof <Cecil@decebal.nl> - 2020-07-29 17:19 +0200
Re: Compare generics (that are numbers) Arne Vajhøj <arne@vajhoej.dk> - 2020-07-29 13:21 -0400
Re: Compare generics (that are numbers) Arne Vajhøj <arne@vajhoej.dk> - 2020-07-29 13:27 -0400
Re: Compare generics (that are numbers) Eric Sosman <esosman@comcast-dot-net.invalid> - 2020-07-29 13:48 -0400
Re: Compare generics (that are numbers) Cecil Westerhof <Cecil@decebal.nl> - 2020-07-29 20:42 +0200
Re: Compare generics (that are numbers) Arne Vajhøj <arne@vajhoej.dk> - 2020-07-29 14:50 -0400
Re: Compare generics (that are numbers) Cecil Westerhof <Cecil@decebal.nl> - 2020-07-29 21:53 +0200
Re: Compare generics (that are numbers) Arne Vajhøj <arne@vajhoej.dk> - 2020-07-29 21:32 -0400
Re: Compare generics (that are numbers) Cecil Westerhof <Cecil@decebal.nl> - 2020-07-30 11:33 +0200
Re: Compare generics (that are numbers) Eric Sosman <esosman@comcast-dot-net.invalid> - 2020-07-30 09:03 -0400
Re: Compare generics (that are numbers) Cecil Westerhof <Cecil@decebal.nl> - 2020-07-30 17:00 +0200
Re: Compare generics (that are numbers) Arne Vajhøj <arne@vajhoej.dk> - 2020-07-30 09:21 -0400
Re: Compare generics (that are numbers) Silvio <silvio@internet.com> - 2020-07-30 08:51 +0200
Re: Compare generics (that are numbers) Cecil Westerhof <Cecil@decebal.nl> - 2020-07-30 11:36 +0200
Re: Compare generics (that are numbers) Marcel Mueller <news.5.maazl@spamgourmet.org> - 2020-07-29 20:59 +0200
csiph-web