android 13 from xiaosuan
This commit is contained in:
commit
aed1b8919e
|
@ -0,0 +1,78 @@
|
|||
// Copyright (C) 2017 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package {
|
||||
default_visibility: ["//visibility:private"],
|
||||
default_applicable_licenses: ["libcore_license"],
|
||||
}
|
||||
|
||||
// Added automatically by a large-scale-change that took the approach of
|
||||
// 'apply every license found to every target'. While this makes sure we respect
|
||||
// every license restriction, it may not be entirely correct.
|
||||
//
|
||||
// e.g. GPL in an MIT project might only apply to the contrib/ directory.
|
||||
//
|
||||
// Please consider splitting the single license below into multiple licenses,
|
||||
// taking care not to lose any license_kind information, and overriding the
|
||||
// default license using the 'licenses: [...]' property on targets as needed.
|
||||
//
|
||||
// For unused files, consider creating a 'filegroup' with "//visibility:private"
|
||||
// to attach the license to, and including a comment whether the files may be
|
||||
// used in the current project.
|
||||
//
|
||||
// large-scale-change included anything that looked like it might be a license
|
||||
// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc.
|
||||
//
|
||||
// Please consider removing redundant or irrelevant files from 'license_text:'.
|
||||
// http://go/android-license-faq
|
||||
license {
|
||||
name: "libcore_license",
|
||||
visibility: [":__subpackages__"],
|
||||
license_kinds: [
|
||||
"SPDX-license-identifier-Apache-2.0",
|
||||
"SPDX-license-identifier-BSD",
|
||||
"SPDX-license-identifier-GPL",
|
||||
"SPDX-license-identifier-GPL-2.0",
|
||||
"SPDX-license-identifier-LGPL",
|
||||
"SPDX-license-identifier-MIT",
|
||||
"SPDX-license-identifier-OpenSSL",
|
||||
"SPDX-license-identifier-Unicode-DFS",
|
||||
"SPDX-license-identifier-W3C",
|
||||
"legacy_unencumbered",
|
||||
],
|
||||
license_text: [
|
||||
"LICENSE",
|
||||
"NOTICE",
|
||||
],
|
||||
}
|
||||
|
||||
build = [
|
||||
"JavaLibrary.bp",
|
||||
"NativeCode.bp",
|
||||
"Extras.bp",
|
||||
]
|
||||
|
||||
java_genrule {
|
||||
name: "notices-for-stubs-jar",
|
||||
tools: ["soong_zip"],
|
||||
tool_files: [
|
||||
"NOTICE",
|
||||
"ojluni/NOTICE",
|
||||
],
|
||||
cmd: "mkdir $(genDir)/NOTICES && " +
|
||||
"cp -f $(location NOTICE) $(genDir)/NOTICES/libcore-NOTICE && " +
|
||||
"cp -f $(location ojluni/NOTICE) $(genDir)/NOTICES/ojluni-NOTICE && " +
|
||||
"$(location soong_zip) -o $(out) -C $(genDir) -D $(genDir)/NOTICES",
|
||||
out: ["notices-for-stubs.jar"],
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2018 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<!-- This test config is placed here for use by atest to enable it to determine
|
||||
which tests to run for core-tests.jar (only). It assumes that the majority
|
||||
of tests for libcore are in the CtsLibcoreTestCases module and therefore
|
||||
does not help for tests where that is not the case.
|
||||
|
||||
This file is effectively a copy of the real CtsLibcoreTestCases
|
||||
AndroidTest.xml file and should track the content of that file.
|
||||
|
||||
TODO: b/114773808 to remove this copied config and execute core-tests.jar
|
||||
directly.
|
||||
-->
|
||||
<configuration description="Config for Libcore test cases">
|
||||
<target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
|
||||
<option name="run-command" value="mkdir -p /data/local/tmp/ctslibcore/java.io.tmpdir" />
|
||||
<option name="run-command" value="mkdir -p /data/local/tmp/ctslibcore/user.home" />
|
||||
<option name="teardown-command" value="rm -rf /data/local/tmp/ctslibcore" />
|
||||
</target_preparer>
|
||||
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
|
||||
<option name="cleanup-apks" value="true" />
|
||||
<!-- this has just the instrumentation which acts as the tests we want to run -->
|
||||
<option name="test-file-name" value="CtsLibcoreTestCases.apk" />
|
||||
</target_preparer>
|
||||
<test class="com.android.compatibility.testtype.LibcoreTest" >
|
||||
<option name="package" value="android.libcore.cts" />
|
||||
<option name="instrumentation-arg" key="filter"
|
||||
value="com.android.cts.core.runner.ExpectationBasedFilter" />
|
||||
<option name="core-expectation" value="/knownfailures.txt" />
|
||||
<option name="runtime-hint" value="45m"/>
|
||||
<!-- 20x default timeout of 600sec -->
|
||||
<option name="shell-timeout" value="12000000"/>
|
||||
<option name="hidden-api-checks" value="false"/>
|
||||
</test>
|
||||
</configuration>
|
|
@ -0,0 +1,69 @@
|
|||
# -*- mode: makefile -*-
|
||||
# Copyright (C) 2007 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
# If you don't need to do a full clean build but would like to touch
|
||||
# a file or delete some intermediate files, add a clean step to the end
|
||||
# of the list. These steps will only be run once, if they haven't been
|
||||
# run before.
|
||||
#
|
||||
# E.g.:
|
||||
# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
|
||||
# $(call add-clean-step, rm -rf $(OUT_DIR)/obj/STATIC_LIBRARIES/libz_intermediates)
|
||||
#
|
||||
# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
|
||||
# files that are missing or have been moved.
|
||||
#
|
||||
# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
|
||||
# Use $(OUT_DIR) to refer to the "out" directory.
|
||||
#
|
||||
# If you need to re-do something that's already mentioned, just copy
|
||||
# the command and add it to the bottom of the list. E.g., if a change
|
||||
# that you made last week required touching a file and a change you
|
||||
# made today requires touching the same file, just copy the old
|
||||
# touch step and add it to the end of the list.
|
||||
#
|
||||
# ************************************************
|
||||
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
|
||||
# ************************************************
|
||||
|
||||
# For example:
|
||||
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
|
||||
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
|
||||
#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
|
||||
#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
|
||||
#$(call add-clean-step, rm -rf $(OUT_DIR)/obj/SHARED_LIBRARIES/libdvm*)
|
||||
$(call add-clean-step, rm -rf $(OUT_DIR)/system/framework/conscrypt-nojarjar.jar)
|
||||
$(call add-clean-step, rm -rf $(OUT_DIR)/system/framework/conscrypt-nojarjar.jar)
|
||||
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core*)
|
||||
$(call add-clean-step, rm -rf $(OUT_DIR)/host/common/obj/JAVA_LIBRARIES/core*)
|
||||
$(call add-clean-step, rm -rf $(OUT_DIR)/system/etc/security/cacerts/*)
|
||||
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core*)
|
||||
$(call add-clean-step, rm -rf $(OUT_DIR)/host/common/obj/JAVA_LIBRARIES/core*)
|
||||
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core*)
|
||||
$(call add-clean-step, rm -rf $(OUT_DIR)/host/common/obj/JAVA_LIBRARIES/core*)
|
||||
|
||||
# Remove core-simple bootclasspath artifacts
|
||||
$(call add-clean-step, rm -rf $(OUT_DIR)/host/linux-x86/framework/*core-simple*)
|
||||
$(call add-clean-step, rm -rf $(OUT_DIR)/host/linux-x86/framework/*/*core-simple*)
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/framework/*core-simple*)
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/framework/*/*core-simple*)
|
||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/framework/*/*core-simple*)
|
||||
$(call add-clean-step, touch -c $(OUT_DIR)/host/linux-x86/bin/dex2oat)
|
||||
$(call add-clean-step, touch -c $(OUT_DIR)/host/linux-x86/bin/dex2oatd)
|
||||
|
||||
# ************************************************
|
||||
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
|
||||
# ************************************************
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2022 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//
|
||||
// Definitions to expose small parts of the core library that are
|
||||
// independent from the whole Android core library.
|
||||
//
|
||||
|
||||
// Java host library containing just the xmlpull sources
|
||||
java_library_host {
|
||||
name: "core-xml-for-host",
|
||||
srcs: ["xml/src/main/java/org/xmlpull/**/*.java"],
|
||||
visibility: ["//packages/modules/Permission:__subpackages__"],
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,347 @@
|
|||
The GNU General Public License (GPL)
|
||||
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license
|
||||
document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your freedom to share
|
||||
and change it. By contrast, the GNU General Public License is intended to
|
||||
guarantee your freedom to share and change free software--to make sure the
|
||||
software is free for all its users. This General Public License applies to
|
||||
most of the Free Software Foundation's software and to any other program whose
|
||||
authors commit to using it. (Some other Free Software Foundation software is
|
||||
covered by the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our
|
||||
General Public Licenses are designed to make sure that you have the freedom to
|
||||
distribute copies of free software (and charge for this service if you wish),
|
||||
that you receive source code or can get it if you want it, that you can change
|
||||
the software or use pieces of it in new free programs; and that you know you
|
||||
can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid anyone to deny
|
||||
you these rights or to ask you to surrender the rights. These restrictions
|
||||
translate to certain responsibilities for you if you distribute copies of the
|
||||
software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for
|
||||
a fee, you must give the recipients all the rights that you have. You must
|
||||
make sure that they, too, receive or can get the source code. And you must
|
||||
show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and (2)
|
||||
offer you this license which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain that
|
||||
everyone understands that there is no warranty for this free software. If the
|
||||
software is modified by someone else and passed on, we want its recipients to
|
||||
know that what they have is not the original, so that any problems introduced
|
||||
by others will not reflect on the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software patents. We
|
||||
wish to avoid the danger that redistributors of a free program will
|
||||
individually obtain patent licenses, in effect making the program proprietary.
|
||||
To prevent this, we have made it clear that any patent must be licensed for
|
||||
everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification
|
||||
follow.
|
||||
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains a notice
|
||||
placed by the copyright holder saying it may be distributed under the terms of
|
||||
this General Public License. The "Program", below, refers to any such program
|
||||
or work, and a "work based on the Program" means either the Program or any
|
||||
derivative work under copyright law: that is to say, a work containing the
|
||||
Program or a portion of it, either verbatim or with modifications and/or
|
||||
translated into another language. (Hereinafter, translation is included
|
||||
without limitation in the term "modification".) Each licensee is addressed as
|
||||
"you".
|
||||
|
||||
Activities other than copying, distribution and modification are not covered by
|
||||
this License; they are outside its scope. The act of running the Program is
|
||||
not restricted, and the output from the Program is covered only if its contents
|
||||
constitute a work based on the Program (independent of having been made by
|
||||
running the Program). Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's source code as
|
||||
you receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice and
|
||||
disclaimer of warranty; keep intact all the notices that refer to this License
|
||||
and to the absence of any warranty; and give any other recipients of the
|
||||
Program a copy of this License along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and you may
|
||||
at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion of it, thus
|
||||
forming a work based on the Program, and copy and distribute such modifications
|
||||
or work under the terms of Section 1 above, provided that you also meet all of
|
||||
these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices stating
|
||||
that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in whole or
|
||||
in part contains or is derived from the Program or any part thereof, to be
|
||||
licensed as a whole at no charge to all third parties under the terms of
|
||||
this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively when run,
|
||||
you must cause it, when started running for such interactive use in the
|
||||
most ordinary way, to print or display an announcement including an
|
||||
appropriate copyright notice and a notice that there is no warranty (or
|
||||
else, saying that you provide a warranty) and that users may redistribute
|
||||
the program under these conditions, and telling the user how to view a copy
|
||||
of this License. (Exception: if the Program itself is interactive but does
|
||||
not normally print such an announcement, your work based on the Program is
|
||||
not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If identifiable
|
||||
sections of that work are not derived from the Program, and can be reasonably
|
||||
considered independent and separate works in themselves, then this License, and
|
||||
its terms, do not apply to those sections when you distribute them as separate
|
||||
works. But when you distribute the same sections as part of a whole which is a
|
||||
work based on the Program, the distribution of the whole must be on the terms
|
||||
of this License, whose permissions for other licensees extend to the entire
|
||||
whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest your
|
||||
rights to work written entirely by you; rather, the intent is to exercise the
|
||||
right to control the distribution of derivative or collective works based on
|
||||
the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program with the
|
||||
Program (or with a work based on the Program) on a volume of a storage or
|
||||
distribution medium does not bring the other work under the scope of this
|
||||
License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it, under
|
||||
Section 2) in object code or executable form under the terms of Sections 1 and
|
||||
2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable source
|
||||
code, which must be distributed under the terms of Sections 1 and 2 above
|
||||
on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three years, to
|
||||
give any third party, for a charge no more than your cost of physically
|
||||
performing source distribution, a complete machine-readable copy of the
|
||||
corresponding source code, to be distributed under the terms of Sections 1
|
||||
and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer to
|
||||
distribute corresponding source code. (This alternative is allowed only
|
||||
for noncommercial distribution and only if you received the program in
|
||||
object code or executable form with such an offer, in accord with
|
||||
Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for making
|
||||
modifications to it. For an executable work, complete source code means all
|
||||
the source code for all modules it contains, plus any associated interface
|
||||
definition files, plus the scripts used to control compilation and installation
|
||||
of the executable. However, as a special exception, the source code
|
||||
distributed need not include anything that is normally distributed (in either
|
||||
source or binary form) with the major components (compiler, kernel, and so on)
|
||||
of the operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the source
|
||||
code from the same place counts as distribution of the source code, even though
|
||||
third parties are not compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program except as
|
||||
expressly provided under this License. Any attempt otherwise to copy, modify,
|
||||
sublicense or distribute the Program is void, and will automatically terminate
|
||||
your rights under this License. However, parties who have received copies, or
|
||||
rights, from you under this License will not have their licenses terminated so
|
||||
long as such parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not signed it.
|
||||
However, nothing else grants you permission to modify or distribute the Program
|
||||
or its derivative works. These actions are prohibited by law if you do not
|
||||
accept this License. Therefore, by modifying or distributing the Program (or
|
||||
any work based on the Program), you indicate your acceptance of this License to
|
||||
do so, and all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the Program),
|
||||
the recipient automatically receives a license from the original licensor to
|
||||
copy, distribute or modify the Program subject to these terms and conditions.
|
||||
You may not impose any further restrictions on the recipients' exercise of the
|
||||
rights granted herein. You are not responsible for enforcing compliance by
|
||||
third parties to this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues), conditions
|
||||
are imposed on you (whether by court order, agreement or otherwise) that
|
||||
contradict the conditions of this License, they do not excuse you from the
|
||||
conditions of this License. If you cannot distribute so as to satisfy
|
||||
simultaneously your obligations under this License and any other pertinent
|
||||
obligations, then as a consequence you may not distribute the Program at all.
|
||||
For example, if a patent license would not permit royalty-free redistribution
|
||||
of the Program by all those who receive copies directly or indirectly through
|
||||
you, then the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply and
|
||||
the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any patents or
|
||||
other property right claims or to contest validity of any such claims; this
|
||||
section has the sole purpose of protecting the integrity of the free software
|
||||
distribution system, which is implemented by public license practices. Many
|
||||
people have made generous contributions to the wide range of software
|
||||
distributed through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing to
|
||||
distribute software through any other system and a licensee cannot impose that
|
||||
choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to be a
|
||||
consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in certain
|
||||
countries either by patents or by copyrighted interfaces, the original
|
||||
copyright holder who places the Program under this License may add an explicit
|
||||
geographical distribution limitation excluding those countries, so that
|
||||
distribution is permitted only in or among countries not thus excluded. In
|
||||
such case, this License incorporates the limitation as if written in the body
|
||||
of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions of the
|
||||
General Public License from time to time. Such new versions will be similar in
|
||||
spirit to the present version, but may differ in detail to address new problems
|
||||
or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any later
|
||||
version", you have the option of following the terms and conditions either of
|
||||
that version or of any later version published by the Free Software Foundation.
|
||||
If the Program does not specify a version number of this License, you may
|
||||
choose any version ever published by the Free Software Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free programs
|
||||
whose distribution conditions are different, write to the author to ask for
|
||||
permission. For software which is copyrighted by the Free Software Foundation,
|
||||
write to the Free Software Foundation; we sometimes make exceptions for this.
|
||||
Our decision will be guided by the two goals of preserving the free status of
|
||||
all derivatives of our free software and of promoting the sharing and reuse of
|
||||
software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
|
||||
THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
|
||||
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
|
||||
PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
|
||||
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
|
||||
YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
|
||||
ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
|
||||
PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
|
||||
INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
|
||||
BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER
|
||||
OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible
|
||||
use to the public, the best way to achieve this is to make it free software
|
||||
which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach
|
||||
them to the start of each source file to most effectively convey the exclusion
|
||||
of warranty; and each file should have at least the "copyright" line and a
|
||||
pointer to where the full notice is found.
|
||||
|
||||
One line to give the program's name and a brief idea of what it does.
|
||||
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this when it
|
||||
starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes
|
||||
with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free
|
||||
software, and you are welcome to redistribute it under certain conditions;
|
||||
type 'show c' for details.
|
||||
|
||||
The hypothetical commands 'show w' and 'show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may be
|
||||
called something other than 'show w' and 'show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary. Here
|
||||
is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
'Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
signature of Ty Coon, 1 April 1989
|
||||
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General Public
|
||||
License instead of this License.
|
||||
|
||||
|
||||
"CLASSPATH" EXCEPTION TO THE GPL
|
||||
|
||||
Certain source files distributed by Oracle America and/or its affiliates are
|
||||
subject to the following clarification and special exception to the GPL, but
|
||||
only where Oracle has expressly included in the particular source file's header
|
||||
the words "Oracle designates this particular file as subject to the "Classpath"
|
||||
exception as provided by Oracle in the LICENSE file that accompanied this code."
|
||||
|
||||
Linking this library statically or dynamically with other modules is making
|
||||
a combined work based on this library. Thus, the terms and conditions of
|
||||
the GNU General Public License cover the whole combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent modules,
|
||||
and to copy and distribute the resulting executable under terms of your
|
||||
choice, provided that you also meet, for each linked independent module,
|
||||
the terms and conditions of the license of that module. An independent
|
||||
module is a module which is not derived from or based on this library. If
|
||||
you modify this library, you may extend this exception to your version of
|
||||
the library, but you are not obligated to do so. If you do not wish to do
|
||||
so, delete this exception statement from your version.
|
|
@ -0,0 +1,117 @@
|
|||
=========================================================================
|
||||
== NOTICE file corresponding to the section 4 d of ==
|
||||
== the Apache License, Version 2.0, ==
|
||||
== in this case for the Android-specific code. ==
|
||||
=========================================================================
|
||||
|
||||
Android Code
|
||||
Copyright 2005-2008 The Android Open Source Project
|
||||
|
||||
This product includes software developed as part of
|
||||
The Android Open Source Project (http://source.android.com).
|
||||
|
||||
=========================================================================
|
||||
== NOTICE file corresponding to the section 4 d of ==
|
||||
== the Apache License, Version 2.0, ==
|
||||
== in this case for the Apache Harmony distribution. ==
|
||||
=========================================================================
|
||||
|
||||
Apache Harmony
|
||||
Copyright 2006 The Apache Software Foundation
|
||||
|
||||
This product includes software developed at
|
||||
The Apache Software Foundation (http://www.apache.org/).
|
||||
|
||||
Portions of Harmony were originally developed by
|
||||
Intel Corporation and are licensed to the Apache Software
|
||||
Foundation under the "Software Grant and Corporate Contribution
|
||||
License Agreement", informally known as the "Intel Harmony CLA".
|
||||
|
||||
|
||||
=========================================================================
|
||||
== NOTICE file for the ICU License. ==
|
||||
=========================================================================
|
||||
|
||||
Copyright (c) 1995-2014 International Business Machines Corporation and others
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, and/or sell copies of the Software, and to permit persons
|
||||
to whom the Software is furnished to do so, provided that the above
|
||||
copyright notice(s) and this permission notice appear in all copies of
|
||||
the Software and that both the above copyright notice(s) and this
|
||||
permission notice appear in supporting documentation.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
|
||||
SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
|
||||
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
||||
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of a copyright holder
|
||||
shall not be used in advertising or otherwise to promote the sale, use
|
||||
or other dealings in this Software without prior written authorization
|
||||
of the copyright holder.
|
||||
|
||||
All trademarks and registered trademarks mentioned herein are the
|
||||
property of their respective owners.
|
||||
|
||||
|
||||
=========================================================================
|
||||
== NOTICE file for the KXML License. ==
|
||||
=========================================================================
|
||||
|
||||
Copyright (c) 2002,2003, Stefan Haustein, Oberhausen, Rhld., Germany
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
=========================================================================
|
||||
== NOTICE file for the W3C License. ==
|
||||
=========================================================================
|
||||
|
||||
Copyright (c) 2000 World Wide Web Consortium, (Massachusetts Institute
|
||||
of Technology, Institut National de Recherche en Informatique et en
|
||||
Automatique, Keio University). All Rights Reserved. This program is
|
||||
distributed under the W3C's Software Intellectual Property License.
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See W3C License http://www.w3.org/Consortium/Legal/ for more details.
|
||||
|
||||
=========================================================================
|
||||
== NOTICE file for the fdlibm License. ==
|
||||
=========================================================================
|
||||
|
||||
Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
|
||||
Developed at SunSoft, a Sun Microsystems, Inc. business.
|
||||
Permission to use, copy, modify, and distribute this
|
||||
software is freely granted, provided that this notice
|
||||
is preserved.
|
|
@ -0,0 +1,267 @@
|
|||
// Copyright (C) 2007 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//
|
||||
// Definitions for building the native code needed for the core library.
|
||||
//
|
||||
|
||||
// Defaults that apply to all of the modules
|
||||
|
||||
cc_defaults {
|
||||
name: "core_native_default_flags",
|
||||
defaults: ["art_module_source_build_defaults"],
|
||||
host_supported: true,
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
],
|
||||
cppflags: ["-DU_USING_ICU_NAMESPACE=0"],
|
||||
|
||||
target: {
|
||||
darwin: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
min_sdk_version: "S",
|
||||
}
|
||||
|
||||
cc_defaults {
|
||||
name: "core_native_default_libs",
|
||||
header_libs: ["jni_headers"],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"liblog",
|
||||
"libnativehelper",
|
||||
],
|
||||
static_libs: ["libnativehelper_compat_libc++"],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "libjavacore",
|
||||
visibility: [
|
||||
"//art/build/apex",
|
||||
"//art/runtime",
|
||||
],
|
||||
apex_available: [
|
||||
"com.android.art",
|
||||
"com.android.art.debug",
|
||||
],
|
||||
defaults: [
|
||||
"core_native_default_flags",
|
||||
"core_native_default_libs",
|
||||
],
|
||||
srcs: [
|
||||
":luni_native_srcs",
|
||||
],
|
||||
shared_libs: [
|
||||
"libandroidio",
|
||||
"libcrypto",
|
||||
"libicu",
|
||||
"libexpat",
|
||||
"libz",
|
||||
],
|
||||
static_libs: [
|
||||
"libziparchive",
|
||||
],
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "libandroidio",
|
||||
visibility: [
|
||||
"//art/build/apex",
|
||||
"//art/build/sdk",
|
||||
"//external/conscrypt",
|
||||
],
|
||||
apex_available: [
|
||||
"com.android.art",
|
||||
"com.android.art.debug",
|
||||
],
|
||||
defaults: [
|
||||
"core_native_default_flags",
|
||||
],
|
||||
shared_libs: [
|
||||
"liblog",
|
||||
],
|
||||
srcs: [
|
||||
":libandroidio_srcs",
|
||||
],
|
||||
stubs: {
|
||||
symbol_file: "libandroidio.map.txt",
|
||||
versions: ["1"],
|
||||
},
|
||||
}
|
||||
|
||||
cc_defaults {
|
||||
name: "libopenjdk_native_defaults",
|
||||
defaults: [
|
||||
"core_native_default_flags",
|
||||
"core_native_default_libs",
|
||||
],
|
||||
srcs: [":libopenjdk_native_srcs"],
|
||||
local_include_dirs: [
|
||||
"luni/src/main/native",
|
||||
],
|
||||
cflags: [
|
||||
// TODO(narayan): Prune down this list of exclusions once the underlying
|
||||
// issues have been fixed. Most of these are small changes except for
|
||||
// -Wunused-parameter.
|
||||
"-Wno-unused-parameter",
|
||||
"-Wno-unused-variable",
|
||||
"-Wno-parentheses-equality",
|
||||
"-Wno-constant-logical-operand",
|
||||
"-Wno-sometimes-uninitialized",
|
||||
],
|
||||
|
||||
shared_libs: [
|
||||
"libandroidio",
|
||||
"libcrypto",
|
||||
"libicu",
|
||||
"libz",
|
||||
],
|
||||
static_libs: [
|
||||
"libfdlibm",
|
||||
],
|
||||
|
||||
target: {
|
||||
musl: {
|
||||
cflags: [
|
||||
// Sigh.
|
||||
"-D_LARGEFILE64_SOURCE",
|
||||
"-D_GNU_SOURCE",
|
||||
"-DLINUX",
|
||||
],
|
||||
},
|
||||
glibc: {
|
||||
cflags: [
|
||||
"-D__GLIBC__",
|
||||
// Sigh.
|
||||
"-D_LARGEFILE64_SOURCE",
|
||||
"-D_GNU_SOURCE",
|
||||
"-DLINUX",
|
||||
],
|
||||
},
|
||||
android: {
|
||||
shared_libs: [
|
||||
"libdl_android",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
notice: "ojluni/NOTICE",
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
name: "libopenjdk",
|
||||
visibility: [
|
||||
"//art/build/apex",
|
||||
],
|
||||
apex_available: [
|
||||
"com.android.art",
|
||||
"com.android.art.debug",
|
||||
],
|
||||
defaults: ["libopenjdk_native_defaults"],
|
||||
shared_libs: [
|
||||
"libopenjdkjvm",
|
||||
],
|
||||
}
|
||||
|
||||
// Debug version of libopenjdk. Depends on libopenjdkjvmd.
|
||||
cc_library_shared {
|
||||
name: "libopenjdkd",
|
||||
visibility: [
|
||||
"//art/build/apex",
|
||||
],
|
||||
apex_available: [
|
||||
"com.android.art.debug",
|
||||
],
|
||||
defaults: ["libopenjdk_native_defaults"],
|
||||
shared_libs: [
|
||||
"libopenjdkjvmd",
|
||||
],
|
||||
}
|
||||
|
||||
// Test JNI library.
|
||||
cc_library_shared {
|
||||
name: "libjavacoretests",
|
||||
visibility: [
|
||||
"//art/build/sdk",
|
||||
"//cts/tests/libcore/luni",
|
||||
],
|
||||
defaults: ["core_native_default_flags"],
|
||||
host_supported: true,
|
||||
|
||||
srcs: [
|
||||
"luni/src/test/native/libcore_dalvik_system_JniTest.cpp",
|
||||
"luni/src/test/native/libcore_java_io_FileTest.cpp",
|
||||
"luni/src/test/native/libcore_java_lang_ThreadTest.cpp",
|
||||
"luni/src/test/native/libcore_java_nio_BufferTest.cpp",
|
||||
"luni/src/test/native/libcore_java_time_BionicTzdbConsistencyTest.cpp",
|
||||
"luni/src/test/native/libcore_libcore_util_NativeAllocationRegistryTest.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"liblog",
|
||||
"libnativehelper",
|
||||
],
|
||||
}
|
||||
|
||||
// Set of gtest unit tests.
|
||||
cc_test {
|
||||
name: "libjavacore-unit-tests",
|
||||
defaults: ["core_native_default_flags"],
|
||||
|
||||
// TODO(b/172480617): Fix this source dependency from
|
||||
// platform_testing/build/tasks/tests/native_test_list.mk.
|
||||
enabled: true,
|
||||
|
||||
// Add -fno-builtin so that the compiler doesn't attempt to inline
|
||||
// memcpy calls that are not really aligned.
|
||||
cflags: ["-fno-builtin"],
|
||||
srcs: [
|
||||
"luni/src/test/native/libcore_io_Memory_test.cpp",
|
||||
// libcore_io_Memory_test.cpp includes libcore_io_Memory.cpp which
|
||||
// depends on JniConstants.cpp (but these are not used in the tests).
|
||||
"luni/src/main/native/JniConstants.cpp",
|
||||
],
|
||||
|
||||
shared_libs: [
|
||||
"liblog",
|
||||
"libnativehelper",
|
||||
],
|
||||
|
||||
static_libs: ["libnativehelper_compat_libc++"],
|
||||
}
|
||||
|
||||
// Set of benchmarks for libjavacore functions.
|
||||
cc_benchmark {
|
||||
name: "libjavacore-benchmarks",
|
||||
defaults: ["core_native_default_flags"],
|
||||
|
||||
// TODO(b/172480617): Fix this source dependency from
|
||||
// platform_testing/build/tasks/tests/native_metric_test_list.mk.
|
||||
enabled: true,
|
||||
|
||||
srcs: [
|
||||
"luni/src/benchmark/native/libcore_io_Memory_bench.cpp",
|
||||
// libcore_io_Memory_bench.cpp includes libcore_io_Memory.cpp which
|
||||
// depends on JniConstants.cpp (but these are not used in the benchmark).
|
||||
"luni/src/main/native/JniConstants.cpp",
|
||||
],
|
||||
test_suites: ["device-tests"],
|
||||
|
||||
shared_libs: [
|
||||
"liblog",
|
||||
"libnativehelper",
|
||||
],
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
# Bug component: 24949
|
||||
|
||||
# Ideally, we would use this reviewer by default, but gerrit and
|
||||
# checkowners.py do not recognize email subaddresses:
|
||||
# android-libcore-team+review@google.com
|
||||
|
||||
# People who can approve changes for submission; don't send review emails to them
|
||||
# unless you know what you're doing.
|
||||
miguelaranda@google.com
|
||||
mingaleev@google.com
|
||||
nikitai@google.com
|
||||
oth@google.com
|
||||
prb@google.com
|
||||
skvadrik@google.com
|
||||
sorinbasca@google.com
|
||||
vichang@google.com
|
||||
|
||||
# Emeritus libcore team members; don't send review emails to them
|
||||
# unless you are in the libcore team.
|
||||
nfuller@google.com #{LAST_RESORT_SUGGESTION}
|
||||
paulduffin@google.com #{LAST_RESORT_SUGGESTION}
|
||||
|
||||
# Don't send these folks any review emails for this project.
|
||||
hboehm@google.com #{LAST_RESORT_SUGGESTION}
|
||||
narayan@google.com #{LAST_RESORT_SUGGESTION}
|
||||
ngeoffray@google.com #{LAST_RESORT_SUGGESTION}
|
||||
rpl@google.com #{LAST_RESORT_SUGGESTION}
|
||||
vmarko@google.com #{LAST_RESORT_SUGGESTION}
|
|
@ -0,0 +1,13 @@
|
|||
[Hook Scripts]
|
||||
# Ensure there are no GPL-licensed files under:
|
||||
# * luni/src/main/java
|
||||
# * json/src/main/java
|
||||
# * xml/src/main/java
|
||||
checkstyle-luni-json-xml = java -jar ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.jar -c tools/checkstyle/checkstyle-forbid-gpl.xml luni/src/main/java json/src/main/java xml/src/main/java
|
||||
|
||||
# Ensure there are no Apache-licensed files under:
|
||||
# * ojluni/src/main/java
|
||||
checkstyle-ojluni = java -jar ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.jar -c tools/checkstyle/checkstyle-forbid-apache.xml ojluni/src/main/java
|
||||
|
||||
[Builtin Hooks]
|
||||
bpfmt = true
|
|
@ -0,0 +1,13 @@
|
|||
Android Core Library
|
||||
|
||||
[Existing open bugs](http://b/issues?q=componentid:24949%20status:open)
|
||||
|
||||
[File a new bug](http://b/new?component=24949)
|
||||
|
||||
[File a new public bug](https://issuetracker.google.com/issues/new?component=192710)
|
||||
|
||||
[Import files from OpenJDK](tools/expected_upstream/README.md)
|
||||
|
||||
[Add nullability annotations](ojluni/annotations/README)
|
||||
|
||||
[Run benchmark tests](benchmarks/README.md)
|
|
@ -0,0 +1,90 @@
|
|||
{
|
||||
"presubmit-large": [
|
||||
{
|
||||
"name": "CtsLibcoreTestCases",
|
||||
"options": [
|
||||
{
|
||||
"exclude-filter": "com.android.org.conscrypt.java.security.AlgorithmParameterGeneratorTestDH"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "com.android.org.conscrypt.java.security.KeyPairGeneratorTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "com.android.org.conscrypt.java.security.SignatureTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "com.android.org.conscrypt.javax.crypto.CipherBasicsTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "com.android.org.conscrypt.javax.net.ssl.KeyManagerFactoryTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "com.android.org.conscrypt.javax.net.ssl.SSLSocketVersionCompatibilityTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "libcore.java.lang.OldRuntimeTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "libcore.java.lang.OldThreadTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "libcore.java.lang.ref.FinalizeTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "libcore.java.math.BigIntegerTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "libcore.java.net.ConcurrentCloseTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "libcore.java.net.OldSocketTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "libcore.java.net.URLConnectionTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "libcore.java.nio.channels.DatagramChannelMulticastTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "libcore.libcore.net.NetworkSecurityPolicyTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "libcore.libcore.util.NativeAllocationRegistryTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "org.apache.harmony.logging.tests.java.util.logging.SocketHandlerTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "org.apache.harmony.tests.java.lang.ObjectTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "org.apache.harmony.tests.java.lang.ProcessManagerTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "org.apache.harmony.tests.java.math.OldBigIntegerTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "org.apache.harmony.tests.java.net.InetAddressThreadTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "org.apache.harmony.tests.java.nio.channels.DatagramChannelTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "org.apache.harmony.tests.java.util.ScannerTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "org.apache.harmony.tests.java.util.TimerTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "org.apache.harmony.tests.java.util.WeakHashMapTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "org.apache.harmony.tests.javax.net.ssl.SSLSessionTest"
|
||||
},
|
||||
{
|
||||
"exclude-filter": "tests.java.sql.StressTest"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,864 @@
|
|||
// Signature format: 2.0
|
||||
package android.compat {
|
||||
|
||||
public final class Compatibility {
|
||||
method public static void clearBehaviorChangeDelegate();
|
||||
method public static void clearOverrides();
|
||||
method public static boolean isChangeEnabled(long);
|
||||
method public static void reportUnconditionalChange(long);
|
||||
method public static void setBehaviorChangeDelegate(android.compat.Compatibility.BehaviorChangeDelegate);
|
||||
method public static void setOverrides(android.compat.Compatibility.ChangeConfig);
|
||||
}
|
||||
|
||||
public static interface Compatibility.BehaviorChangeDelegate {
|
||||
method public default boolean isChangeEnabled(long);
|
||||
method public default void onChangeReported(long);
|
||||
}
|
||||
|
||||
public static final class Compatibility.ChangeConfig {
|
||||
ctor public Compatibility.ChangeConfig(@NonNull java.util.Set<java.lang.Long>, @NonNull java.util.Set<java.lang.Long>);
|
||||
method @NonNull public long[] getDisabledChangesArray();
|
||||
method @NonNull public java.util.Set<java.lang.Long> getDisabledSet();
|
||||
method @NonNull public long[] getEnabledChangesArray();
|
||||
method @NonNull public java.util.Set<java.lang.Long> getEnabledSet();
|
||||
method public boolean isEmpty();
|
||||
method public boolean isForceDisabled(long);
|
||||
method public boolean isForceEnabled(long);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package android.system {
|
||||
|
||||
public final class NetlinkSocketAddress extends java.net.SocketAddress {
|
||||
ctor public NetlinkSocketAddress(int, int);
|
||||
method public int getGroupsMask();
|
||||
method public int getPortId();
|
||||
}
|
||||
|
||||
public final class Os {
|
||||
method @Nullable public static android.system.StructCapUserData[] capget(@NonNull android.system.StructCapUserHeader) throws android.system.ErrnoException;
|
||||
method public static void capset(@NonNull android.system.StructCapUserHeader, @NonNull android.system.StructCapUserData[]) throws android.system.ErrnoException;
|
||||
method public static int getpgid(int) throws android.system.ErrnoException;
|
||||
method @Nullable public static android.system.StructRlimit getrlimit(int) throws android.system.ErrnoException;
|
||||
method public static int getsockoptInt(@NonNull java.io.FileDescriptor, int, int) throws android.system.ErrnoException;
|
||||
method @Nullable public static android.system.StructLinger getsockoptLinger(@NonNull java.io.FileDescriptor, int, int) throws android.system.ErrnoException;
|
||||
method public static int ioctlInt(@NonNull java.io.FileDescriptor, int) throws android.system.ErrnoException;
|
||||
method @Nullable public static java.io.FileDescriptor[] pipe2(int) throws android.system.ErrnoException;
|
||||
method @Nullable public static String realpath(@Nullable String) throws android.system.ErrnoException;
|
||||
method public static void setpgid(int, int) throws android.system.ErrnoException;
|
||||
method public static void setregid(int, int) throws android.system.ErrnoException;
|
||||
method public static void setreuid(int, int) throws android.system.ErrnoException;
|
||||
method public static void setsockoptIfreq(@NonNull java.io.FileDescriptor, int, int, @Nullable String) throws android.system.ErrnoException;
|
||||
method public static void setsockoptLinger(@NonNull java.io.FileDescriptor, int, int, @NonNull android.system.StructLinger) throws android.system.ErrnoException;
|
||||
method public static long splice(@NonNull java.io.FileDescriptor, @Nullable android.system.Int64Ref, @NonNull java.io.FileDescriptor, @Nullable android.system.Int64Ref, long, int) throws android.system.ErrnoException;
|
||||
method public static void unlink(@Nullable String) throws android.system.ErrnoException;
|
||||
}
|
||||
|
||||
public final class OsConstants {
|
||||
method public static int CAP_TO_INDEX(int);
|
||||
method public static int CAP_TO_MASK(int);
|
||||
field public static final int ARPHRD_LOOPBACK;
|
||||
field public static final int EUSERS;
|
||||
field public static final int MAP_POPULATE;
|
||||
field public static final int O_DIRECT;
|
||||
field public static final int PR_CAP_AMBIENT;
|
||||
field public static final int PR_CAP_AMBIENT_RAISE;
|
||||
field public static final int RLIMIT_NOFILE;
|
||||
field public static final int RTMGRP_IPV4_IFADDR;
|
||||
field public static final int SPLICE_F_MORE;
|
||||
field public static final int SPLICE_F_MOVE;
|
||||
field public static final int TIOCOUTQ;
|
||||
field public static final int UDP_ENCAP;
|
||||
field public static final int UDP_ENCAP_ESPINUDP;
|
||||
field public static final int XATTR_CREATE;
|
||||
field public static final int XATTR_REPLACE;
|
||||
field public static final int _LINUX_CAPABILITY_VERSION_3;
|
||||
}
|
||||
|
||||
public final class PacketSocketAddress extends java.net.SocketAddress {
|
||||
ctor public PacketSocketAddress(int, int, byte[]);
|
||||
}
|
||||
|
||||
public final class StructCapUserData {
|
||||
ctor public StructCapUserData(int, int, int);
|
||||
field public final int effective;
|
||||
field public final int inheritable;
|
||||
field public final int permitted;
|
||||
}
|
||||
|
||||
public final class StructCapUserHeader {
|
||||
ctor public StructCapUserHeader(int, int);
|
||||
}
|
||||
|
||||
public final class StructLinger {
|
||||
ctor public StructLinger(int, int);
|
||||
method public boolean isOn();
|
||||
field public final int l_linger;
|
||||
}
|
||||
|
||||
public final class StructRlimit {
|
||||
field public final long rlim_cur;
|
||||
}
|
||||
|
||||
public final class UnixSocketAddress extends java.net.SocketAddress {
|
||||
method public static android.system.UnixSocketAddress createFileSystem(String);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package com.android.okhttp.internalandroidapi {
|
||||
|
||||
public final class AndroidResponseCacheAdapter {
|
||||
ctor public AndroidResponseCacheAdapter(@NonNull com.android.okhttp.internalandroidapi.HasCacheHolder.CacheHolder);
|
||||
method public void close() throws java.io.IOException;
|
||||
method public void delete() throws java.io.IOException;
|
||||
method public void flush() throws java.io.IOException;
|
||||
method @Nullable public java.net.CacheResponse get(@NonNull java.net.URI, @NonNull String, @Nullable java.util.Map<java.lang.String,java.util.List<java.lang.String>>) throws java.io.IOException;
|
||||
method @NonNull public com.android.okhttp.internalandroidapi.HasCacheHolder.CacheHolder getCacheHolder();
|
||||
method public int getHitCount();
|
||||
method public long getMaxSize();
|
||||
method public int getNetworkCount();
|
||||
method public int getRequestCount();
|
||||
method public long getSize() throws java.io.IOException;
|
||||
method @Nullable public java.net.CacheRequest put(@NonNull java.net.URI, @NonNull java.net.URLConnection) throws java.io.IOException;
|
||||
}
|
||||
|
||||
public interface HasCacheHolder {
|
||||
method @NonNull public com.android.okhttp.internalandroidapi.HasCacheHolder.CacheHolder getCacheHolder();
|
||||
}
|
||||
|
||||
public static final class HasCacheHolder.CacheHolder {
|
||||
method @NonNull public static com.android.okhttp.internalandroidapi.HasCacheHolder.CacheHolder create(@NonNull java.io.File, long);
|
||||
method public boolean isEquivalent(@NonNull java.io.File, long);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package dalvik.annotation.codegen {
|
||||
|
||||
@java.lang.annotation.Repeatable(CovariantReturnType.CovariantReturnTypes.class) @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) @java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD}) public @interface CovariantReturnType {
|
||||
method public abstract int presentAfter();
|
||||
method public abstract Class<?> returnType();
|
||||
}
|
||||
|
||||
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) @java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD}) public static @interface CovariantReturnType.CovariantReturnTypes {
|
||||
method public abstract dalvik.annotation.codegen.CovariantReturnType[] value();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package dalvik.annotation.optimization {
|
||||
|
||||
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) @java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD) public @interface CriticalNative {
|
||||
}
|
||||
|
||||
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) @java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD) public @interface FastNative {
|
||||
}
|
||||
|
||||
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) @java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD) public @interface NeverCompile {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package dalvik.system {
|
||||
|
||||
public final class AnnotatedStackTraceElement {
|
||||
method @Nullable public Object getBlockedOn();
|
||||
method @Nullable public Object[] getHeldLocks();
|
||||
method @NonNull public StackTraceElement getStackTraceElement();
|
||||
}
|
||||
|
||||
public class AppSpecializationHooks {
|
||||
method public static void handleCompatChangesBeforeBindingApplication();
|
||||
}
|
||||
|
||||
public class BaseDexClassLoader extends java.lang.ClassLoader {
|
||||
method public void addDexPath(@Nullable String);
|
||||
method public void addNativePath(@NonNull java.util.Collection<java.lang.String>);
|
||||
method @NonNull public String getLdLibraryPath();
|
||||
method public void reportClassLoaderChain();
|
||||
method public static void setReporter(@Nullable dalvik.system.BaseDexClassLoader.Reporter);
|
||||
}
|
||||
|
||||
public static interface BaseDexClassLoader.Reporter {
|
||||
method public void report(@NonNull java.util.Map<java.lang.String,java.lang.String>);
|
||||
}
|
||||
|
||||
public final class BlockGuard {
|
||||
method @NonNull public static dalvik.system.BlockGuard.Policy getThreadPolicy();
|
||||
method @NonNull public static dalvik.system.BlockGuard.VmPolicy getVmPolicy();
|
||||
method public static void setThreadPolicy(@NonNull dalvik.system.BlockGuard.Policy);
|
||||
method public static void setVmPolicy(@NonNull dalvik.system.BlockGuard.VmPolicy);
|
||||
field public static final dalvik.system.BlockGuard.Policy LAX_POLICY;
|
||||
field public static final dalvik.system.BlockGuard.VmPolicy LAX_VM_POLICY;
|
||||
}
|
||||
|
||||
public static interface BlockGuard.Policy {
|
||||
method public int getPolicyMask();
|
||||
method public void onReadFromDisk();
|
||||
method public void onUnbufferedIO();
|
||||
method public void onWriteToDisk();
|
||||
}
|
||||
|
||||
public static interface BlockGuard.VmPolicy {
|
||||
method public void onPathAccess(@NonNull String);
|
||||
}
|
||||
|
||||
public final class CloseGuard {
|
||||
method public void close();
|
||||
method public static dalvik.system.CloseGuard get();
|
||||
method public static dalvik.system.CloseGuard.Reporter getReporter();
|
||||
method public void open(String);
|
||||
method public void openWithCallSite(String, String);
|
||||
method public static void setEnabled(boolean);
|
||||
method public static void setReporter(dalvik.system.CloseGuard.Reporter);
|
||||
method public void warnIfOpen();
|
||||
}
|
||||
|
||||
public static interface CloseGuard.Reporter {
|
||||
method public void report(String, Throwable);
|
||||
method public default void report(String);
|
||||
}
|
||||
|
||||
public final class DelegateLastClassLoader extends dalvik.system.PathClassLoader {
|
||||
ctor public DelegateLastClassLoader(String, String, ClassLoader, ClassLoader[]);
|
||||
ctor public DelegateLastClassLoader(String, String, ClassLoader, ClassLoader[], ClassLoader[]);
|
||||
}
|
||||
|
||||
@Deprecated public final class DexFile {
|
||||
method @Deprecated @NonNull public static dalvik.system.DexFile.OptimizationInfo getDexFileOptimizationInfo(@NonNull String, @NonNull String) throws java.io.FileNotFoundException;
|
||||
method @Deprecated @Nullable public static String[] getDexFileOutputPaths(@NonNull String, @NonNull String) throws java.io.FileNotFoundException;
|
||||
method @Deprecated public static int getDexOptNeeded(@NonNull String, @NonNull String, @NonNull String, @Nullable String, boolean, boolean) throws java.io.FileNotFoundException, java.io.IOException;
|
||||
method @Deprecated @NonNull public static String getSafeModeCompilerFilter(@NonNull String);
|
||||
method @Deprecated public static boolean isProfileGuidedCompilerFilter(@NonNull String);
|
||||
method @Deprecated public static boolean isValidCompilerFilter(@NonNull String);
|
||||
field @Deprecated public static final int DEX2OAT_FOR_FILTER = 3; // 0x3
|
||||
field @Deprecated public static final int NO_DEXOPT_NEEDED = 0; // 0x0
|
||||
}
|
||||
|
||||
@Deprecated public static final class DexFile.OptimizationInfo {
|
||||
method @Deprecated @NonNull public String getReason();
|
||||
method @Deprecated @NonNull public String getStatus();
|
||||
}
|
||||
|
||||
public class PathClassLoader extends dalvik.system.BaseDexClassLoader {
|
||||
ctor public PathClassLoader(@NonNull String, @Nullable String, @Nullable ClassLoader, @Nullable ClassLoader[]);
|
||||
ctor public PathClassLoader(@NonNull String, @Nullable String, @Nullable ClassLoader, @Nullable ClassLoader[], @Nullable ClassLoader[]);
|
||||
}
|
||||
|
||||
public final class RuntimeHooks {
|
||||
method public static void setTimeZoneIdSupplier(@NonNull java.util.function.Supplier<java.lang.String>);
|
||||
method public static void setUncaughtExceptionPreHandler(@Nullable java.lang.Thread.UncaughtExceptionHandler);
|
||||
}
|
||||
|
||||
public abstract class SocketTagger {
|
||||
ctor public SocketTagger();
|
||||
method public static dalvik.system.SocketTagger get();
|
||||
method public static void set(dalvik.system.SocketTagger);
|
||||
method public abstract void tag(java.io.FileDescriptor) throws java.net.SocketException;
|
||||
method public final void tag(java.net.Socket) throws java.net.SocketException;
|
||||
method public final void tag(java.net.DatagramSocket) throws java.net.SocketException;
|
||||
method public abstract void untag(java.io.FileDescriptor) throws java.net.SocketException;
|
||||
method public final void untag(java.net.Socket) throws java.net.SocketException;
|
||||
method public final void untag(java.net.DatagramSocket) throws java.net.SocketException;
|
||||
}
|
||||
|
||||
public final class VMDebug {
|
||||
method public static void attachAgent(String, ClassLoader) throws java.io.IOException;
|
||||
method public static long countInstancesOfClass(Class, boolean);
|
||||
method public static long[] countInstancesOfClasses(Class[], boolean);
|
||||
method public static void dumpHprofData(String) throws java.io.IOException;
|
||||
method public static void dumpHprofData(String, java.io.FileDescriptor) throws java.io.IOException;
|
||||
method public static void dumpHprofDataDdms();
|
||||
method public static void dumpReferenceTables();
|
||||
method public static int getAllocCount(int);
|
||||
method @dalvik.annotation.optimization.FastNative public static int getLoadedClassCount();
|
||||
method public static int getMethodTracingMode();
|
||||
method public static String getRuntimeStat(String);
|
||||
method public static java.util.Map<java.lang.String,java.lang.String> getRuntimeStats();
|
||||
method public static String[] getVmFeatureList();
|
||||
method @dalvik.annotation.optimization.FastNative public static boolean isDebuggerConnected();
|
||||
method @dalvik.annotation.optimization.FastNative public static boolean isDebuggingEnabled();
|
||||
method @dalvik.annotation.optimization.FastNative public static long lastDebuggerActivity();
|
||||
method @dalvik.annotation.optimization.FastNative public static void printLoadedClasses(int);
|
||||
method public static void resetAllocCount(int);
|
||||
method public static void setAllocTrackerStackDepth(int);
|
||||
method public static void startAllocCounting();
|
||||
method public static void startMethodTracing(String, int, int, boolean, int);
|
||||
method public static void startMethodTracing(String, java.io.FileDescriptor, int, int, boolean, int, boolean);
|
||||
method public static void startMethodTracingDdms(int, int, boolean, int);
|
||||
method public static void stopAllocCounting();
|
||||
method public static void stopMethodTracing();
|
||||
method @dalvik.annotation.optimization.FastNative public static long threadCpuTimeNanos();
|
||||
field public static final int KIND_ALL_COUNTS = -1; // 0xffffffff
|
||||
field public static final int KIND_GLOBAL_ALLOCATED_BYTES = 2; // 0x2
|
||||
field public static final int KIND_GLOBAL_ALLOCATED_OBJECTS = 1; // 0x1
|
||||
field public static final int KIND_GLOBAL_CLASS_INIT_COUNT = 32; // 0x20
|
||||
field public static final int KIND_GLOBAL_CLASS_INIT_TIME = 64; // 0x40
|
||||
field public static final int KIND_GLOBAL_FREED_BYTES = 8; // 0x8
|
||||
field public static final int KIND_GLOBAL_FREED_OBJECTS = 4; // 0x4
|
||||
field public static final int KIND_GLOBAL_GC_INVOCATIONS = 16; // 0x10
|
||||
field public static final int KIND_THREAD_ALLOCATED_BYTES = 131072; // 0x20000
|
||||
field public static final int KIND_THREAD_ALLOCATED_OBJECTS = 65536; // 0x10000
|
||||
field public static final int KIND_THREAD_GC_INVOCATIONS = 1048576; // 0x100000
|
||||
field public static final int TRACE_COUNT_ALLOCS = 1; // 0x1
|
||||
}
|
||||
|
||||
public final class VMRuntime {
|
||||
method @dalvik.annotation.optimization.FastNative public long addressOf(Object);
|
||||
method public static void bootCompleted();
|
||||
method public void clampGrowthLimit();
|
||||
method public void clearGrowthLimit();
|
||||
method public static String getCurrentInstructionSet();
|
||||
method public static String getInstructionSet(String);
|
||||
method public static dalvik.system.VMRuntime getRuntime();
|
||||
method public int getTargetSdkVersion();
|
||||
method @dalvik.annotation.optimization.FastNative public boolean is64Bit();
|
||||
method public static boolean is64BitAbi(String);
|
||||
method public static boolean is64BitInstructionSet(String);
|
||||
method @dalvik.annotation.optimization.FastNative public boolean isCheckJniEnabled();
|
||||
method @dalvik.annotation.optimization.FastNative public boolean isNativeDebuggable();
|
||||
method public static boolean isValidClassLoaderContext(String);
|
||||
method @dalvik.annotation.optimization.FastNative public Object newNonMovableArray(Class<?>, int);
|
||||
method @dalvik.annotation.optimization.FastNative public Object newUnpaddedArray(Class<?>, int);
|
||||
method public void notifyStartupCompleted();
|
||||
method public void preloadDexCaches();
|
||||
method public static void registerAppInfo(String, String, String, String[], int);
|
||||
method public void registerNativeAllocation(long);
|
||||
method @Deprecated public void registerNativeAllocation(int);
|
||||
method public void registerNativeFree(long);
|
||||
method @Deprecated public void registerNativeFree(int);
|
||||
method public static void registerSensitiveThread();
|
||||
method public void requestConcurrentGC();
|
||||
method public static void resetJitCounters();
|
||||
method public static void setDedupeHiddenApiWarnings(boolean);
|
||||
method public void setDisabledCompatChanges(long[]);
|
||||
method public void setHiddenApiAccessLogSamplingRate(int);
|
||||
method public void setHiddenApiExemptions(String[]);
|
||||
method public static void setHiddenApiUsageLogger(dalvik.system.VMRuntime.HiddenApiUsageLogger);
|
||||
method public static void setNonSdkApiUsageConsumer(java.util.function.Consumer<java.lang.String>);
|
||||
method public static void setProcessDataDirectory(String);
|
||||
method public static void setProcessPackageName(String);
|
||||
method public void setTargetSdkVersion(int);
|
||||
method public void updateProcessState(int);
|
||||
method public String vmInstructionSet();
|
||||
method public String vmLibrary();
|
||||
field public static final int CODE_PATH_TYPE_PRIMARY_APK = 1; // 0x1
|
||||
field public static final int CODE_PATH_TYPE_SECONDARY_DEX = 4; // 0x4
|
||||
field public static final int CODE_PATH_TYPE_SPLIT_APK = 2; // 0x2
|
||||
field public static final int SDK_VERSION_CUR_DEVELOPMENT = 10000; // 0x2710
|
||||
}
|
||||
|
||||
public static interface VMRuntime.HiddenApiUsageLogger {
|
||||
method public void hiddenApiUsed(int, String, String, int, boolean);
|
||||
field public static final int ACCESS_METHOD_JNI = 2; // 0x2
|
||||
field public static final int ACCESS_METHOD_LINKING = 3; // 0x3
|
||||
field public static final int ACCESS_METHOD_NONE = 0; // 0x0
|
||||
field public static final int ACCESS_METHOD_REFLECTION = 1; // 0x1
|
||||
}
|
||||
|
||||
public final class VMStack {
|
||||
method @Nullable @dalvik.annotation.optimization.FastNative public static dalvik.system.AnnotatedStackTraceElement[] getAnnotatedThreadStackTrace(Thread);
|
||||
}
|
||||
|
||||
public final class ZygoteHooks {
|
||||
method public static void gcAndFinalize();
|
||||
method public static boolean isIndefiniteThreadSuspensionSafe();
|
||||
method public static void onBeginPreload();
|
||||
method public static void onEndPreload();
|
||||
method public static void postForkChild(int, boolean, boolean, String);
|
||||
method public static void postForkCommon();
|
||||
method public static void postForkSystemServer(int);
|
||||
method public static void preFork();
|
||||
method public static void startZygoteNoThreadCreation();
|
||||
method public static void stopZygoteNoThreadCreation();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package java.io {
|
||||
|
||||
public final class FileDescriptor {
|
||||
method public int getInt$();
|
||||
method public void setInt$(int);
|
||||
}
|
||||
|
||||
public class FileInputStream extends java.io.InputStream {
|
||||
ctor public FileInputStream(java.io.FileDescriptor, boolean);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package java.lang {
|
||||
|
||||
public class Thread implements java.lang.Runnable {
|
||||
method public static java.lang.Thread.UncaughtExceptionHandler getUncaughtExceptionPreHandler();
|
||||
method public static void setUncaughtExceptionPreHandler(java.lang.Thread.UncaughtExceptionHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package java.net {
|
||||
|
||||
public class DatagramSocket implements java.io.Closeable {
|
||||
method public java.io.FileDescriptor getFileDescriptor$();
|
||||
}
|
||||
|
||||
public final class Inet4Address extends java.net.InetAddress {
|
||||
field public static final java.net.InetAddress ALL;
|
||||
field public static final java.net.InetAddress ANY;
|
||||
field public static final java.net.InetAddress LOOPBACK;
|
||||
}
|
||||
|
||||
public final class Inet6Address extends java.net.InetAddress {
|
||||
field public static final java.net.InetAddress ANY;
|
||||
field public static final java.net.InetAddress LOOPBACK;
|
||||
}
|
||||
|
||||
public class InetAddress implements java.io.Serializable {
|
||||
method public static void clearDnsCache();
|
||||
method @NonNull public static java.net.InetAddress[] getAllByNameOnNet(@Nullable String, int) throws java.net.UnknownHostException;
|
||||
method @NonNull public static java.net.InetAddress getByNameOnNet(@Nullable String, int) throws java.net.UnknownHostException;
|
||||
method @Deprecated public static boolean isNumeric(String);
|
||||
method @Deprecated public static java.net.InetAddress parseNumericAddress(String);
|
||||
}
|
||||
|
||||
public class InetSocketAddress extends java.net.SocketAddress {
|
||||
ctor public InetSocketAddress();
|
||||
}
|
||||
|
||||
public class ServerSocket implements java.io.Closeable {
|
||||
method public java.net.SocketImpl getImpl() throws java.net.SocketException;
|
||||
}
|
||||
|
||||
public class Socket implements java.io.Closeable {
|
||||
method public java.io.FileDescriptor getFileDescriptor$();
|
||||
}
|
||||
|
||||
public abstract class SocketImpl implements java.net.SocketOptions {
|
||||
method public java.io.FileDescriptor getFD$();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package java.nio {
|
||||
|
||||
public abstract class ByteBuffer extends java.nio.Buffer implements java.lang.Comparable<java.nio.ByteBuffer> {
|
||||
method public void setAccessible(boolean);
|
||||
}
|
||||
|
||||
public class DirectByteBuffer extends java.nio.MappedByteBuffer {
|
||||
ctor public DirectByteBuffer(int, long, java.io.FileDescriptor, Runnable, boolean);
|
||||
method public final long address();
|
||||
method public final void setAccessible(boolean);
|
||||
}
|
||||
|
||||
public final class NIOAccess {
|
||||
method public static Object getBaseArray(java.nio.Buffer);
|
||||
method public static int getBaseArrayOffset(java.nio.Buffer);
|
||||
}
|
||||
|
||||
public final class NioUtils {
|
||||
method public static void freeDirectBuffer(java.nio.ByteBuffer);
|
||||
method public static byte[] unsafeArray(java.nio.ByteBuffer);
|
||||
method public static int unsafeArrayOffset(java.nio.ByteBuffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package java.security {
|
||||
|
||||
public abstract class Provider extends java.util.Properties {
|
||||
method public void warmUpServiceProvision();
|
||||
}
|
||||
|
||||
public abstract class Signature extends java.security.SignatureSpi {
|
||||
method public java.security.SignatureSpi getCurrentSpi();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package java.text {
|
||||
|
||||
public abstract class DateFormat extends java.text.Format {
|
||||
method public static final void set24HourTimePref(Boolean);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package java.util {
|
||||
|
||||
public class LinkedHashMap<K, V> extends java.util.HashMap<K,V> implements java.util.Map<K,V> {
|
||||
method public java.util.Map.Entry<K,V> eldest();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package java.util.zip {
|
||||
|
||||
public class ZipEntry implements java.lang.Cloneable {
|
||||
method public long getDataOffset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package javax.crypto {
|
||||
|
||||
public class Cipher {
|
||||
method public javax.crypto.CipherSpi getCurrentSpi();
|
||||
}
|
||||
|
||||
public class Mac implements java.lang.Cloneable {
|
||||
method public javax.crypto.MacSpi getCurrentSpi();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package javax.net.ssl {
|
||||
|
||||
public abstract class HttpsURLConnection extends java.net.HttpURLConnection {
|
||||
method public static javax.net.ssl.HostnameVerifier getStrictHostnameVerifier();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package libcore.content.type {
|
||||
|
||||
public final class MimeMap {
|
||||
method @NonNull public libcore.content.type.MimeMap.Builder buildUpon();
|
||||
method @NonNull public static libcore.content.type.MimeMap.Builder builder();
|
||||
method @NonNull public java.util.Set<java.lang.String> extensions();
|
||||
method @NonNull public static libcore.content.type.MimeMap getDefault();
|
||||
method @Nullable public String guessExtensionFromMimeType(@Nullable String);
|
||||
method @Nullable public String guessMimeTypeFromExtension(@Nullable String);
|
||||
method public boolean hasExtension(@Nullable String);
|
||||
method public boolean hasMimeType(@Nullable String);
|
||||
method @NonNull public java.util.Set<java.lang.String> mimeTypes();
|
||||
method public static void setDefaultSupplier(@NonNull java.util.function.Supplier<libcore.content.type.MimeMap>);
|
||||
}
|
||||
|
||||
public static final class MimeMap.Builder {
|
||||
method @NonNull public libcore.content.type.MimeMap.Builder addMimeMapping(@NonNull String, @NonNull java.util.List<java.lang.String>);
|
||||
method @NonNull public libcore.content.type.MimeMap build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package libcore.io {
|
||||
|
||||
public class ForwardingOs implements libcore.io.Os {
|
||||
ctor protected ForwardingOs(@NonNull libcore.io.Os);
|
||||
method public boolean access(@Nullable String, int) throws android.system.ErrnoException;
|
||||
method public java.io.FileDescriptor open(@Nullable String, int, int) throws android.system.ErrnoException;
|
||||
method public void remove(@Nullable String) throws android.system.ErrnoException;
|
||||
method public void rename(@Nullable String, @Nullable String) throws android.system.ErrnoException;
|
||||
method @Nullable public android.system.StructStat stat(@Nullable String) throws android.system.ErrnoException;
|
||||
method public void unlink(@Nullable String) throws android.system.ErrnoException;
|
||||
}
|
||||
|
||||
public final class IoBridge {
|
||||
method public static void closeAndSignalBlockedThreads(@NonNull java.io.FileDescriptor) throws java.io.IOException;
|
||||
method @NonNull public static java.io.FileDescriptor open(@NonNull String, int) throws java.io.FileNotFoundException;
|
||||
method public static int read(@NonNull java.io.FileDescriptor, @NonNull byte[], int, int) throws java.io.IOException;
|
||||
method public static void write(@NonNull java.io.FileDescriptor, @NonNull byte[], int, int) throws java.io.IOException;
|
||||
}
|
||||
|
||||
public final class IoUtils {
|
||||
method public static int acquireRawFd(@NonNull java.io.FileDescriptor);
|
||||
method public static void close(@Nullable java.io.FileDescriptor) throws java.io.IOException;
|
||||
method public static void closeQuietly(@Nullable AutoCloseable);
|
||||
method public static void closeQuietly(@Nullable java.io.FileDescriptor);
|
||||
method public static void closeQuietly(@Nullable java.net.Socket);
|
||||
method @NonNull public static byte[] readFileAsByteArray(@NonNull String) throws java.io.IOException;
|
||||
method @NonNull public static String readFileAsString(@NonNull String) throws java.io.IOException;
|
||||
method public static void setBlocking(@NonNull java.io.FileDescriptor, boolean) throws java.io.IOException;
|
||||
method public static void setFdOwner(@NonNull java.io.FileDescriptor, @NonNull Object);
|
||||
}
|
||||
|
||||
public final class Memory {
|
||||
method public static void memmove(@NonNull Object, int, @NonNull Object, int, long);
|
||||
method public static int peekInt(@NonNull byte[], int, @NonNull java.nio.ByteOrder);
|
||||
method public static short peekShort(@NonNull byte[], int, @NonNull java.nio.ByteOrder);
|
||||
method public static void pokeInt(@NonNull byte[], int, int, @NonNull java.nio.ByteOrder);
|
||||
method public static void pokeLong(@NonNull byte[], int, long, @NonNull java.nio.ByteOrder);
|
||||
method public static void pokeShort(@NonNull byte[], int, short, @NonNull java.nio.ByteOrder);
|
||||
}
|
||||
|
||||
public interface Os {
|
||||
method public static boolean compareAndSetDefault(libcore.io.Os, libcore.io.Os);
|
||||
method public static libcore.io.Os getDefault();
|
||||
}
|
||||
|
||||
public final class Streams {
|
||||
method public static int copy(@NonNull java.io.InputStream, @NonNull java.io.OutputStream) throws java.io.IOException;
|
||||
method public static void readFully(@NonNull java.io.InputStream, @NonNull byte[]) throws java.io.IOException;
|
||||
method @NonNull public static byte[] readFully(@NonNull java.io.InputStream) throws java.io.IOException;
|
||||
method @NonNull public static String readFully(@NonNull java.io.Reader) throws java.io.IOException;
|
||||
method @NonNull public static byte[] readFullyNoClose(@NonNull java.io.InputStream) throws java.io.IOException;
|
||||
method public static int readSingleByte(@NonNull java.io.InputStream) throws java.io.IOException;
|
||||
method public static long skipByReading(@NonNull java.io.InputStream, long) throws java.io.IOException;
|
||||
method public static void writeSingleByte(@NonNull java.io.OutputStream, int) throws java.io.IOException;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package libcore.net {
|
||||
|
||||
public class InetAddressUtils {
|
||||
method public static boolean isNumericAddress(String);
|
||||
method public static java.net.InetAddress parseNumericAddress(String);
|
||||
}
|
||||
|
||||
public abstract class NetworkSecurityPolicy {
|
||||
ctor public NetworkSecurityPolicy();
|
||||
method public static libcore.net.NetworkSecurityPolicy getInstance();
|
||||
method public abstract boolean isCertificateTransparencyVerificationRequired(String);
|
||||
method public abstract boolean isCleartextTrafficPermitted();
|
||||
method public abstract boolean isCleartextTrafficPermitted(String);
|
||||
method public static void setInstance(libcore.net.NetworkSecurityPolicy);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package libcore.net.event {
|
||||
|
||||
public final class NetworkEventDispatcher {
|
||||
method public void dispatchNetworkConfigurationChange();
|
||||
method public static libcore.net.event.NetworkEventDispatcher getInstance();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package libcore.net.http {
|
||||
|
||||
public interface Dns {
|
||||
method @NonNull public java.util.List<java.net.InetAddress> lookup(@Nullable String) throws java.net.UnknownHostException;
|
||||
}
|
||||
|
||||
public class HttpURLConnectionFactory {
|
||||
method @NonNull public static libcore.net.http.HttpURLConnectionFactory createInstance();
|
||||
method public java.net.URLConnection openConnection(@NonNull java.net.URL, @NonNull javax.net.SocketFactory, @NonNull java.net.Proxy) throws java.io.IOException;
|
||||
method public void setDns(@NonNull libcore.net.http.Dns);
|
||||
method public void setNewConnectionPool(int, long, @NonNull java.util.concurrent.TimeUnit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package libcore.util {
|
||||
|
||||
public final class EmptyArray {
|
||||
field @NonNull public static final boolean[] BOOLEAN;
|
||||
field @NonNull public static final byte[] BYTE;
|
||||
field @NonNull public static final float[] FLOAT;
|
||||
field @NonNull public static final int[] INT;
|
||||
field @NonNull public static final long[] LONG;
|
||||
field @NonNull public static final Object[] OBJECT;
|
||||
field @NonNull public static final String[] STRING;
|
||||
}
|
||||
|
||||
public final class FP16 {
|
||||
method public static short ceil(short);
|
||||
method public static int compare(short, short);
|
||||
method public static boolean equals(short, short);
|
||||
method public static short floor(short);
|
||||
method public static boolean greater(short, short);
|
||||
method public static boolean greaterEquals(short, short);
|
||||
method public static boolean isInfinite(short);
|
||||
method public static boolean isNaN(short);
|
||||
method public static boolean isNormalized(short);
|
||||
method public static boolean less(short, short);
|
||||
method public static boolean lessEquals(short, short);
|
||||
method public static short max(short, short);
|
||||
method public static short min(short, short);
|
||||
method public static short rint(short);
|
||||
method public static float toFloat(short);
|
||||
method public static short toHalf(float);
|
||||
method public static String toHexString(short);
|
||||
method public static short trunc(short);
|
||||
field public static final short EPSILON = 5120; // 0x1400
|
||||
field public static final int EXPONENT_BIAS = 15; // 0xf
|
||||
field public static final int EXPONENT_SHIFT = 10; // 0xa
|
||||
field public static final int EXPONENT_SIGNIFICAND_MASK = 32767; // 0x7fff
|
||||
field public static final short LOWEST_VALUE = -1025; // 0xfffffbff
|
||||
field public static final int MAX_EXPONENT = 15; // 0xf
|
||||
field public static final short MAX_VALUE = 31743; // 0x7bff
|
||||
field public static final int MIN_EXPONENT = -14; // 0xfffffff2
|
||||
field public static final short MIN_NORMAL = 1024; // 0x400
|
||||
field public static final short MIN_VALUE = 1; // 0x1
|
||||
field public static final short NEGATIVE_INFINITY = -1024; // 0xfffffc00
|
||||
field public static final short NEGATIVE_ZERO = -32768; // 0xffff8000
|
||||
field public static final short NaN = 32256; // 0x7e00
|
||||
field public static final short POSITIVE_INFINITY = 31744; // 0x7c00
|
||||
field public static final short POSITIVE_ZERO = 0; // 0x0
|
||||
field public static final int SHIFTED_EXPONENT_MASK = 31; // 0x1f
|
||||
field public static final int SIGNIFICAND_MASK = 1023; // 0x3ff
|
||||
field public static final int SIGN_MASK = 32768; // 0x8000
|
||||
field public static final int SIGN_SHIFT = 15; // 0xf
|
||||
field public static final int SIZE = 16; // 0x10
|
||||
}
|
||||
|
||||
public class HexEncoding {
|
||||
method public static byte[] decode(String) throws java.lang.IllegalArgumentException;
|
||||
method public static byte[] decode(String, boolean) throws java.lang.IllegalArgumentException;
|
||||
method public static byte[] decode(char[]) throws java.lang.IllegalArgumentException;
|
||||
method public static byte[] decode(char[], boolean) throws java.lang.IllegalArgumentException;
|
||||
method public static char[] encode(byte[]);
|
||||
method public static char[] encode(byte[], boolean);
|
||||
method public static char[] encode(byte[], int, int);
|
||||
method public static String encodeToString(byte, boolean);
|
||||
method public static String encodeToString(byte[]);
|
||||
method public static String encodeToString(byte[], boolean);
|
||||
}
|
||||
|
||||
public class NativeAllocationRegistry {
|
||||
ctor public NativeAllocationRegistry(@NonNull ClassLoader, long, long);
|
||||
method public static void applyFreeFunction(long, long);
|
||||
method public static libcore.util.NativeAllocationRegistry createMalloced(@NonNull ClassLoader, long, long);
|
||||
method public static libcore.util.NativeAllocationRegistry createMalloced(@NonNull ClassLoader, long);
|
||||
method public static libcore.util.NativeAllocationRegistry createNonmalloced(@NonNull ClassLoader, long, long);
|
||||
method @NonNull public Runnable registerNativeAllocation(@NonNull Object, long);
|
||||
}
|
||||
|
||||
public class SneakyThrow {
|
||||
method public static void sneakyThrow(@NonNull Throwable);
|
||||
}
|
||||
|
||||
public class XmlObjectFactory {
|
||||
method @NonNull public static org.xml.sax.XMLReader newXMLReader();
|
||||
method @NonNull public static org.xmlpull.v1.XmlPullParser newXmlPullParser();
|
||||
method @NonNull public static org.xmlpull.v1.XmlSerializer newXmlSerializer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package org.apache.harmony.dalvik.ddmc {
|
||||
|
||||
public class Chunk {
|
||||
ctor public Chunk(int, byte[], int, int);
|
||||
ctor public Chunk(int, java.nio.ByteBuffer);
|
||||
field public int type;
|
||||
}
|
||||
|
||||
public abstract class ChunkHandler {
|
||||
ctor public ChunkHandler();
|
||||
method public static org.apache.harmony.dalvik.ddmc.Chunk createFailChunk(int, String);
|
||||
method public abstract org.apache.harmony.dalvik.ddmc.Chunk handleChunk(org.apache.harmony.dalvik.ddmc.Chunk);
|
||||
method public static String name(int);
|
||||
method public abstract void onConnected();
|
||||
method public abstract void onDisconnected();
|
||||
method public static int type(String);
|
||||
method public static java.nio.ByteBuffer wrapChunk(org.apache.harmony.dalvik.ddmc.Chunk);
|
||||
field public static final java.nio.ByteOrder CHUNK_ORDER;
|
||||
}
|
||||
|
||||
public final class DdmServer {
|
||||
method public static void registerHandler(int, org.apache.harmony.dalvik.ddmc.ChunkHandler);
|
||||
method public static void registrationComplete();
|
||||
method public static void sendChunk(org.apache.harmony.dalvik.ddmc.Chunk);
|
||||
method public static org.apache.harmony.dalvik.ddmc.ChunkHandler unregisterHandler(int);
|
||||
}
|
||||
|
||||
public final class DdmVmInternal {
|
||||
method public static void setRecentAllocationsTrackingEnabled(boolean);
|
||||
method public static void setThreadNotifyEnabled(boolean);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package org.json {
|
||||
|
||||
public class JSONObject {
|
||||
method @NonNull public java.util.Set<java.lang.String> keySet();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package sun.misc {
|
||||
|
||||
public class Cleaner extends java.lang.ref.PhantomReference<java.lang.Object> {
|
||||
method public void clean();
|
||||
method public static sun.misc.Cleaner create(Object, Runnable);
|
||||
}
|
||||
|
||||
public final class Unsafe {
|
||||
method public int arrayBaseOffset(Class);
|
||||
method public int arrayIndexScale(Class);
|
||||
method @dalvik.annotation.optimization.FastNative public void copyMemory(long, long, long);
|
||||
method @dalvik.annotation.optimization.FastNative public boolean getBoolean(Object, long);
|
||||
method @dalvik.annotation.optimization.FastNative public byte getByte(Object, long);
|
||||
method @dalvik.annotation.optimization.FastNative public byte getByte(long);
|
||||
method @dalvik.annotation.optimization.FastNative public double getDouble(Object, long);
|
||||
method @dalvik.annotation.optimization.FastNative public double getDouble(long);
|
||||
method @dalvik.annotation.optimization.FastNative public float getFloat(Object, long);
|
||||
method @dalvik.annotation.optimization.FastNative public float getFloat(long);
|
||||
method @dalvik.annotation.optimization.FastNative public int getInt(Object, long);
|
||||
method @dalvik.annotation.optimization.FastNative public int getInt(long);
|
||||
method @dalvik.annotation.optimization.FastNative public long getLong(Object, long);
|
||||
method @dalvik.annotation.optimization.FastNative public long getLong(long);
|
||||
method @dalvik.annotation.optimization.FastNative public Object getObject(Object, long);
|
||||
method public static sun.misc.Unsafe getUnsafe();
|
||||
method public long objectFieldOffset(java.lang.reflect.Field);
|
||||
method @dalvik.annotation.optimization.FastNative public void putBoolean(Object, long, boolean);
|
||||
method @dalvik.annotation.optimization.FastNative public void putByte(Object, long, byte);
|
||||
method @dalvik.annotation.optimization.FastNative public void putByte(long, byte);
|
||||
method @dalvik.annotation.optimization.FastNative public void putDouble(Object, long, double);
|
||||
method @dalvik.annotation.optimization.FastNative public void putDouble(long, double);
|
||||
method @dalvik.annotation.optimization.FastNative public void putFloat(Object, long, float);
|
||||
method @dalvik.annotation.optimization.FastNative public void putFloat(long, float);
|
||||
method @dalvik.annotation.optimization.FastNative public void putInt(Object, long, int);
|
||||
method @dalvik.annotation.optimization.FastNative public void putInt(long, int);
|
||||
method @dalvik.annotation.optimization.FastNative public void putLong(Object, long, long);
|
||||
method @dalvik.annotation.optimization.FastNative public void putLong(long, long);
|
||||
method @dalvik.annotation.optimization.FastNative public void putObject(Object, long, Object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package sun.security.jca {
|
||||
|
||||
public class Providers {
|
||||
method public static Object startJarVerification();
|
||||
method public static void stopJarVerification(Object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package sun.security.pkcs {
|
||||
|
||||
public class PKCS7 {
|
||||
ctor public PKCS7(java.io.InputStream) throws java.io.IOException, sun.security.pkcs.ParsingException;
|
||||
ctor public PKCS7(byte[]) throws sun.security.pkcs.ParsingException;
|
||||
method public java.security.cert.X509Certificate[] getCertificates();
|
||||
method public sun.security.pkcs.SignerInfo[] getSignerInfos();
|
||||
method public sun.security.pkcs.SignerInfo verify(sun.security.pkcs.SignerInfo, java.io.InputStream) throws java.io.IOException, java.security.NoSuchAlgorithmException, java.security.SignatureException;
|
||||
method public sun.security.pkcs.SignerInfo[] verify(byte[]) throws java.security.NoSuchAlgorithmException, java.security.SignatureException;
|
||||
}
|
||||
|
||||
public class ParsingException extends java.io.IOException {
|
||||
}
|
||||
|
||||
public class SignerInfo {
|
||||
ctor public SignerInfo();
|
||||
method public java.util.ArrayList<java.security.cert.X509Certificate> getCertificateChain(sun.security.pkcs.PKCS7) throws java.io.IOException;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package sun.security.util {
|
||||
|
||||
public final class ObjectIdentifier implements java.io.Serializable {
|
||||
ctor public ObjectIdentifier(String) throws java.io.IOException;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package sun.security.x509 {
|
||||
|
||||
public class AlgorithmId implements java.io.Serializable {
|
||||
ctor public AlgorithmId(sun.security.util.ObjectIdentifier);
|
||||
method public String getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
// Signature format: 2.0
|
|
@ -0,0 +1 @@
|
|||
// Signature format: 2.0
|
|
@ -0,0 +1 @@
|
|||
// Signature format: 2.0
|
|
@ -0,0 +1 @@
|
|||
// Signature format: 2.0
|
|
@ -0,0 +1,61 @@
|
|||
// Copyright (C) 2019 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package {
|
||||
// http://go/android-license-faq
|
||||
// A large-scale-change added 'default_applicable_licenses' to import
|
||||
// the below license kinds from "libcore_license":
|
||||
// SPDX-license-identifier-Apache-2.0
|
||||
default_applicable_licenses: ["libcore_license"],
|
||||
}
|
||||
|
||||
java_test {
|
||||
name: "benchmarks",
|
||||
srcs: ["src/**/*.java"],
|
||||
static_libs: [
|
||||
"mockwebserver",
|
||||
"core-tests-support",
|
||||
],
|
||||
sdk_version: "none",
|
||||
system_modules: "core-all-system-modules",
|
||||
libs: [
|
||||
"caliper-api-target",
|
||||
"android.test.base",
|
||||
],
|
||||
errorprone: {
|
||||
javacflags: ["-Xep:EqualsNull:WARN"],
|
||||
},
|
||||
}
|
||||
|
||||
android_test {
|
||||
name: "LibcoreBenchmarkTests",
|
||||
srcs: [],
|
||||
static_libs: [
|
||||
"androidx.benchmark_benchmark-junit4",
|
||||
"LibcoreBenchmarkTestsLib",
|
||||
],
|
||||
sdk_version: "current",
|
||||
manifest: "AndroidManifest.xml",
|
||||
test_suites: ["general-tests"],
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "LibcoreBenchmarkTestsLib",
|
||||
srcs: ["src_androidx/**/*.java"],
|
||||
static_libs: [
|
||||
"androidx.benchmark_benchmark-junit4",
|
||||
],
|
||||
sdk_version: "none",
|
||||
system_modules: "core-all-system-modules",
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2021 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="libcore.benchmark">
|
||||
<!-- Important: disable debuggable for accurate performance results -->
|
||||
<application android:debuggable="false"/>
|
||||
|
||||
<instrumentation
|
||||
android:name="androidx.benchmark.junit4.AndroidBenchmarkRunner"
|
||||
android:targetPackage="libcore.benchmark"/>
|
||||
</manifest>
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2021 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<configuration description="Runs libcore benchmark tests">
|
||||
<!--Test app needs to be installed when we change its settings below-->
|
||||
<target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
|
||||
<option name="test-file-name" value="LibcoreBenchmarkTests.apk"/>
|
||||
<option name="cleanup-apks" value="true"/>
|
||||
</target_preparer>
|
||||
|
||||
<option name="test-suite-tag" value="apct"/>
|
||||
<option name="test-tag" value="LibcoreBenchmarkTests"/>
|
||||
<test class="com.android.tradefed.testtype.AndroidJUnitTest">
|
||||
<option name="package" value="libcore.benchmark"/>
|
||||
<option name="runner" value="androidx.benchmark.junit4.AndroidBenchmarkRunner"/>
|
||||
<option name="hidden-api-checks" value="false"/>
|
||||
<option name="instrumentation-arg" key="androidx.benchmark.suppressErrors"
|
||||
value="EMULATOR,LOW-BATTERY"/>
|
||||
</test>
|
||||
</configuration>
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
# Run Caliper benchmark tests using vogar on a rooted device
|
||||
|
||||
- It uses the [Caliper library](https://github.com/google/caliper) developed by Google.
|
||||
- Vogar source codes can be found at `external/vogar`.
|
||||
|
||||
1. Preparation
|
||||
|
||||
```shell
|
||||
# vogar requires com.android.art.testing
|
||||
m vogar com.android.art.testing
|
||||
# remount if you haven't done so.
|
||||
adb root && adb remount && adb reboot && adb wait-for-device root
|
||||
cd libcore/benchmarks/src
|
||||
```
|
||||
|
||||
Extra options to reduce noise:
|
||||
```shell
|
||||
adb shell stop # to kill frameworks and zygote
|
||||
```
|
||||
|
||||
2. Run an individual test
|
||||
|
||||
```shell
|
||||
vogar --benchmark benchmarks/regression/ScannerBenchmark.java
|
||||
```
|
||||
|
||||
The source code of the tests can be found at `src/benchmarks/`
|
||||
|
||||
# Run Jetpack benchmark tests
|
||||
Docs about Jetpack Benchmark can be found at
|
||||
[https://developer.android.com/studio/profile/benchmarking-overview]()
|
||||
|
||||
1. Preparation
|
||||
|
||||
To lock CPU clocks on a rooted device,
|
||||
run the script provided at [https://developer.android.com/studio/profile/run-benchmarks-in-ci#clock-locking]().
|
||||
|
||||
2. Run an individual test
|
||||
```shell
|
||||
atest LibcoreBenchmarkTests:libcore.benchmark.FormatterTest#stringFormatNumber_allLocales
|
||||
```
|
||||
|
||||
The source code of the tests can be found at `src_androidx/libcore/benchmark/`
|
||||
|
||||
## Outdated documentation / Not working
|
||||
|
||||
###VM Options
|
||||
|
||||
|
||||
The VM's configuration will have a substantial impact on performance.
|
||||
Use Caliper's -J<name> <value 1>,<value 2>,<value 3> syntax to compare different VM options. For example:
|
||||
```shell
|
||||
vogar --benchmark ~/svn/dalvik/benchmarks/regression/CrespoFileIoRegressionBenchmark.java \
|
||||
-- -Jgc -Xgc:noconcurrent,-Xgc:concurrent -Jint -Xint:fast,-Xint:jit,-Xint:portable
|
||||
```
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/**
|
||||
* What do various kinds of addition cost?
|
||||
*/
|
||||
public class AdditionBenchmark {
|
||||
public int timeAddConstantToLocalInt(int reps) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result += 123;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeAddTwoLocalInts(int reps) {
|
||||
int result = 0;
|
||||
int constant = 123;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result += constant;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public long timeAddConstantToLocalLong(int reps) {
|
||||
long result = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result += 123L;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public long timeAddTwoLocalLongs(int reps) {
|
||||
long result = 0;
|
||||
long constant = 123L;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result += constant;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public float timeAddConstantToLocalFloat(int reps) {
|
||||
float result = 0.0f;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result += 123.0f;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public float timeAddTwoLocalFloats(int reps) {
|
||||
float result = 0.0f;
|
||||
float constant = 123.0f;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result += constant;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public double timeAddConstantToLocalDouble(int reps) {
|
||||
double result = 0.0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result += 123.0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public double timeAddTwoLocalDoubles(int reps) {
|
||||
double result = 0.0;
|
||||
double constant = 123.0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result += constant;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ArrayCopyBenchmark {
|
||||
public void timeManualArrayCopy(int reps) {
|
||||
char[] src = new char[8192];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
char[] dst = new char[8192];
|
||||
for (int i = 0; i < 8192; ++i) {
|
||||
dst[i] = src[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void time_System_arrayCopy(int reps) {
|
||||
char[] src = new char[8192];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
char[] dst = new char[8192];
|
||||
System.arraycopy(src, 0, dst, 0, 8192);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_Arrays_copyOf(int reps) {
|
||||
char[] src = new char[8192];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
char[] dst = Arrays.copyOf(src, 8192);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_Arrays_copyOfRange(int reps) {
|
||||
char[] src = new char[8192];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
char[] dst = Arrays.copyOfRange(src, 0, 8192);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/**
|
||||
* How do various ways of iterating through an array compare?
|
||||
*/
|
||||
public class ArrayIterationBenchmark {
|
||||
Foo[] mArray = new Foo[27];
|
||||
{
|
||||
for (int i = 0; i < mArray.length; ++i) mArray[i] = new Foo();
|
||||
}
|
||||
public void timeArrayIteration(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < mArray.length; i++) {
|
||||
sum += mArray[i].mSplat;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void timeArrayIterationCached(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
int sum = 0;
|
||||
Foo[] localArray = mArray;
|
||||
int len = localArray.length;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
sum += localArray[i].mSplat;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void timeArrayIterationForEach(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
int sum = 0;
|
||||
for (Foo a: mArray) {
|
||||
sum += a.mSplat;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Is a hand-coded counted loop through an ArrayList cheaper than enhanced for?
|
||||
*/
|
||||
public class ArrayListIterationBenchmark {
|
||||
ArrayList<Foo> mList = new ArrayList<Foo>();
|
||||
{
|
||||
for (int i = 0; i < 27; ++i) mList.add(new Foo());
|
||||
}
|
||||
public void timeArrayListIterationIndexed(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
int sum = 0;
|
||||
ArrayList<Foo> list = mList;
|
||||
int len = list.size();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
sum += list.get(i).mSplat;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void timeArrayListIterationForEach(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
int sum = 0;
|
||||
for (Foo a : mList) {
|
||||
sum += a.mSplat;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,235 @@
|
|||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* Tries to measure important BigInteger operations across a variety of BigInteger sizes.
|
||||
* Note that BigInteger implementations commonly need to use wildly different algorithms
|
||||
* for different sizes, so relative performance may change substantially depending on the
|
||||
* size of the integer.
|
||||
* This is not structured as a proper benchmark; just run main(), e.g. with
|
||||
* vogar libcore/benchmarks/src/benchmarks/BigIntegerBenchmark.java.
|
||||
*/
|
||||
public class BigIntegerBenchmark {
|
||||
private static final boolean PRINT_TIMES = true;
|
||||
|
||||
private static long getStartTime() {
|
||||
if (PRINT_TIMES) {
|
||||
return System.nanoTime();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static void printTime(String s, long startTime, int reps) {
|
||||
if (PRINT_TIMES) {
|
||||
System.out.println(s
|
||||
+ (double)(System.nanoTime() - startTime) / 1000.0 / reps + " usecs / iter");
|
||||
}
|
||||
}
|
||||
|
||||
// A simple sum of products computation, mostly so we can check timing in the
|
||||
// absence of any division. Computes the sum from 1 to n of ((10^prec) << 30) + 1)^2,
|
||||
// repeating the multiplication, but not addition of 1, each time through the loop.
|
||||
// Check the last few bits of the result as we go. Assumes n < 2^30.
|
||||
// Note that we're actually squaring values in computing the product.
|
||||
// That affects the algorithm used by some implementations.
|
||||
private static void inner(int n, int prec) {
|
||||
BigInteger big = BigInteger.TEN.pow(prec).shiftLeft(30).add(BigInteger.ONE);
|
||||
BigInteger sum = BigInteger.ZERO;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
sum = sum.add(big.multiply(big));
|
||||
}
|
||||
if (sum.and(BigInteger.valueOf(0x3fffffff)).intValue() != n) {
|
||||
System.out.println("inner() got " + sum.and(BigInteger.valueOf(0x3fffffff))
|
||||
+ " instead of " + n);
|
||||
}
|
||||
}
|
||||
|
||||
// Execute the above rep times, optionally timing it.
|
||||
private static void repeatInner(int n, int prec, int rep) {
|
||||
long startTime = getStartTime();
|
||||
for (int i = 0; i < rep; ++i) {
|
||||
inner(n, prec);
|
||||
}
|
||||
printTime("inner(" + n + "," + prec + ") took ", startTime, rep);
|
||||
}
|
||||
|
||||
// Approximate the sum of the first 1000 terms of the harmonic series (sum of 1/m as m
|
||||
// goes from 1 to n) to about prec digits. The result has an implicit decimal point
|
||||
// prec digits from the right.
|
||||
private static BigInteger harmonic1000(int prec) {
|
||||
BigInteger scaledOne = BigInteger.TEN.pow(prec);
|
||||
BigInteger sum = BigInteger.ZERO;
|
||||
for (int i = 1; i <= 1000; ++i) {
|
||||
sum = sum.add(scaledOne.divide(BigInteger.valueOf(i)));
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
// Execute the above rep times, optionally timing it.
|
||||
// Check results for equality, and print one, to compaare against reference.
|
||||
private static void repeatHarmonic1000(int prec, int rep) {
|
||||
long startTime = getStartTime();
|
||||
BigInteger refRes = harmonic1000(prec);
|
||||
for (int i = 1; i < rep; ++i) {
|
||||
BigInteger newRes = harmonic1000(prec);
|
||||
if (!newRes.equals(refRes)) {
|
||||
throw new AssertionError(newRes + " != " + refRes);
|
||||
}
|
||||
}
|
||||
printTime("harmonic(1000) to " + prec + " digits took ", startTime, rep);
|
||||
if (prec >= 50 && !refRes.toString()
|
||||
.startsWith("748547086055034491265651820433390017652167916970")) {
|
||||
throw new AssertionError("harmanic(" + prec + ") incorrectly produced " + refRes);
|
||||
}
|
||||
}
|
||||
|
||||
// Repeatedly execute just the base conversion from the last test, allowing
|
||||
// us to time and check it for consistency as well.
|
||||
private static void repeatToString(int prec, int rep) {
|
||||
BigInteger refRes = harmonic1000(prec);
|
||||
long startTime = getStartTime();
|
||||
String refString = refRes.toString();
|
||||
for (int i = 1; i < rep; ++i) {
|
||||
// Disguise refRes to avoid compiler optimization issues.
|
||||
BigInteger newRes = refRes.shiftLeft(30).add(BigInteger.valueOf(i)).shiftRight(30);
|
||||
// The time-consuming part:
|
||||
String newString = newRes.toString();
|
||||
if (!newString.equals(refString)) {
|
||||
System.out.println(newString + " != " + refString);
|
||||
}
|
||||
}
|
||||
printTime("toString(" + prec + ") took ", startTime, rep);
|
||||
}
|
||||
|
||||
// Compute base^exp, where base and result are scaled/multiplied by scaleBy to make them
|
||||
// integers. exp >= 0 .
|
||||
private static BigInteger myPow(BigInteger base, int exp, BigInteger scaleBy) {
|
||||
if (exp == 0) {
|
||||
return scaleBy; // Return one.
|
||||
} else if ((exp & 1) != 0) {
|
||||
BigInteger tmp = myPow(base, exp - 1, scaleBy);
|
||||
return tmp.multiply(base).divide(scaleBy);
|
||||
} else {
|
||||
BigInteger tmp = myPow(base, exp / 2, scaleBy);
|
||||
return tmp.multiply(tmp).divide(scaleBy);
|
||||
}
|
||||
}
|
||||
|
||||
// Approximate e by computing (1 + 1/n)^n to prec decimal digits.
|
||||
// This isn't necessarily a very good approximation to e.
|
||||
// Return the result, scaled by 10^prec.
|
||||
private static BigInteger eApprox(int n, int prec) {
|
||||
BigInteger scaledOne = BigInteger.TEN.pow(prec);
|
||||
BigInteger base = scaledOne.add(scaledOne.divide(BigInteger.valueOf(n)));
|
||||
return myPow(base, n, scaledOne);
|
||||
}
|
||||
|
||||
// Repeatedly execute and check the above, printing one of the results
|
||||
// to compare to reference.
|
||||
private static void repeatEApprox(int n, int prec, int rep) {
|
||||
long startTime = getStartTime();
|
||||
BigInteger refRes = eApprox(n, prec);
|
||||
for (int i = 1; i < rep; ++i) {
|
||||
BigInteger newRes = eApprox(n, prec);
|
||||
if (!newRes.equals(refRes)) {
|
||||
throw new AssertionError(newRes + " != " + refRes);
|
||||
}
|
||||
}
|
||||
printTime("eApprox(" + n + "," + prec + ") took ", startTime, rep);
|
||||
if (n >= 100000 && prec >= 10 && !refRes.toString().startsWith("271826")) {
|
||||
throw new AssertionError("eApprox(" + n + "," + prec + ") incorrectly produced "
|
||||
+ refRes);
|
||||
}
|
||||
}
|
||||
|
||||
// Test / time modPow()
|
||||
private static void repeatModPow(int len, int rep) {
|
||||
BigInteger odd1 = BigInteger.TEN.pow(len / 2).add(BigInteger.ONE);
|
||||
BigInteger odd2 = BigInteger.TEN.pow(len / 2).add(BigInteger.valueOf(17));
|
||||
BigInteger product = odd1.multiply(odd2);
|
||||
BigInteger exponent = BigInteger.TEN.pow(len / 2 - 1);
|
||||
BigInteger base = BigInteger.TEN.pow(len / 4);
|
||||
long startTime = getStartTime();
|
||||
BigInteger lastRes = null;
|
||||
for (int i = 0; i < rep; ++i) {
|
||||
BigInteger newRes = base.modPow(exponent, product);
|
||||
if (i != 0 && !newRes.equals(lastRes)) {
|
||||
System.out.println(newRes + " != " + lastRes);
|
||||
}
|
||||
lastRes = newRes;
|
||||
}
|
||||
printTime("ModPow() at decimal length " + len + " took ", startTime, rep);
|
||||
if (!lastRes.mod(odd1).equals(base.modPow(exponent, odd1))) {
|
||||
throw new AssertionError("ModPow() result incorrect mod odd1:" + odd1
|
||||
+ "; lastRes.mod(odd1)=" + lastRes.mod(odd1) + " vs. "
|
||||
+ "base.modPow(exponent, odd1)=" + base.modPow(exponent, odd1) + " base="
|
||||
+ base + " exponent=" + exponent);
|
||||
}
|
||||
if (!lastRes.mod(odd2).equals(base.modPow(exponent, odd2))) {
|
||||
throw new AssertionError("ModPow() result incorrect mod odd2");
|
||||
}
|
||||
}
|
||||
|
||||
// Test / time modInverse()
|
||||
private static void repeatModInverse(int len, int rep) {
|
||||
BigInteger odd1 = BigInteger.TEN.pow(len / 2).add(BigInteger.ONE);
|
||||
BigInteger odd2 = BigInteger.TEN.pow(len / 2).add(BigInteger.valueOf(17));
|
||||
BigInteger product = odd1.multiply(odd2);
|
||||
BigInteger arg = BigInteger.ONE.shiftLeft(len / 4);
|
||||
long startTime = getStartTime();
|
||||
BigInteger lastRes = null;
|
||||
for (int i = 0; i < rep; ++i) {
|
||||
BigInteger newRes = arg.modInverse(product);
|
||||
if (i != 0 && !newRes.equals(lastRes)) {
|
||||
System.out.println(newRes + " != " + lastRes);
|
||||
}
|
||||
lastRes = newRes;
|
||||
}
|
||||
printTime("ModInverse() at decimal length " + len + " took ", startTime, rep);
|
||||
if (!lastRes.mod(odd1).equals(arg.modInverse(odd1))) {
|
||||
throw new AssertionError("ModInverse() result incorrect mod odd1");
|
||||
}
|
||||
if (!lastRes.mod(odd2).equals(arg.modInverse(odd2))) {
|
||||
throw new AssertionError("ModInverse() result incorrect mod odd2");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
for (int i = 10; i <= 10_000; i *= 10) {
|
||||
repeatInner(1000, i, PRINT_TIMES ? Math.min(20_000 / i, 3_000) : 2);
|
||||
}
|
||||
for (int i = 5; i <= 5_000; i *= 10) {
|
||||
repeatHarmonic1000(i, PRINT_TIMES ? Math.min(20_000 / i, 3_000) : 2);
|
||||
}
|
||||
for (int i = 5; i <= 5_000; i *= 10) {
|
||||
repeatToString(i, PRINT_TIMES ? Math.min(20_000 / i, 3_000) : 2);
|
||||
}
|
||||
for (int i = 10; i <= 10_000; i *= 10) {
|
||||
repeatEApprox(100_000, i, PRINT_TIMES ? 50_000 / i : 2);
|
||||
}
|
||||
for (int i = 5; i <= 5_000; i *= 10) {
|
||||
repeatModPow(i, PRINT_TIMES ? 10_000 / i : 2);
|
||||
}
|
||||
for (int i = 10; i <= 10_000; i *= 10) {
|
||||
repeatModInverse(i, PRINT_TIMES ? 20_000 / i : 2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (C) 2011 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Param;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Random;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public final class BufferedZipFileBenchmark {
|
||||
@Param({"128", "1024", "8192", "65536"}) int compressedSize;
|
||||
@Param({"4", "32", "128"}) int readSize;
|
||||
|
||||
private File file;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
System.setProperty("java.io.tmpdir", "/data/local/tmp");
|
||||
file = File.createTempFile(getClass().getName(), ".zip");
|
||||
file.deleteOnExit();
|
||||
|
||||
Random random = new Random(0);
|
||||
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
|
||||
byte[] data = new byte[8192];
|
||||
out.putNextEntry(new ZipEntry("entry.data"));
|
||||
int written = 0;
|
||||
while (written < compressedSize) {
|
||||
random.nextBytes(data);
|
||||
int toWrite = Math.min(compressedSize - written, data.length);
|
||||
out.write(data, 0, toWrite);
|
||||
written += toWrite;
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
|
||||
public void timeUnbufferedRead(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
ZipFile zipFile = new ZipFile(file);
|
||||
ZipEntry entry = zipFile.getEntry("entry.data");
|
||||
InputStream in = zipFile.getInputStream(entry);
|
||||
byte[] buffer = new byte[readSize];
|
||||
while (in.read(buffer) != -1) {
|
||||
}
|
||||
in.close();
|
||||
zipFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeBufferedRead(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
ZipFile zipFile = new ZipFile(file);
|
||||
ZipEntry entry = zipFile.getEntry("entry.data");
|
||||
InputStream in = new BufferedInputStream(zipFile.getInputStream(entry));
|
||||
byte[] buffer = new byte[readSize];
|
||||
while (in.read(buffer) != -1) {
|
||||
}
|
||||
in.close();
|
||||
zipFile.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class ClassLoaderResourceBenchmark {
|
||||
|
||||
private static final String EXISTENT_RESOURCE = "java/util/logging/logging.properties";
|
||||
private static final String MISSING_RESOURCE = "missing_entry";
|
||||
|
||||
public void timeGetBootResource_hit(int reps) {
|
||||
ClassLoader currentClassLoader = getClass().getClassLoader();
|
||||
Assert.assertNotNull(currentClassLoader.getResource(EXISTENT_RESOURCE));
|
||||
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
currentClassLoader.getResource(EXISTENT_RESOURCE);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetBootResource_miss(int reps) {
|
||||
ClassLoader currentClassLoader = getClass().getClassLoader();
|
||||
Assert.assertNull(currentClassLoader.getResource(MISSING_RESOURCE));
|
||||
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
currentClassLoader.getResource(MISSING_RESOURCE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Benchmark;
|
||||
import com.google.caliper.Param;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DeepArrayOpsBenchmark {
|
||||
@Param({"0001", "0004", "0016", "0256", "2048"}) int arrayLength;
|
||||
|
||||
private Object[] array;
|
||||
private Object[] array2;
|
||||
|
||||
@BeforeExperiment public void setUp() throws Exception {
|
||||
array = new Object[arrayLength * 14];
|
||||
array2 = new Object[arrayLength * 14];
|
||||
for (int i = 0; i < arrayLength; i += 14) {
|
||||
array[i] = new IntWrapper(i);
|
||||
array2[i] = new IntWrapper(i);
|
||||
|
||||
array[i + 1] = new16ElementObjectarray();
|
||||
array2[i + 1] = new16ElementObjectarray();
|
||||
|
||||
array[i + 2] = new boolean[16];
|
||||
array2[i + 2] = new boolean[16];
|
||||
|
||||
array[i + 3] = new byte[16];
|
||||
array2[i + 3] = new byte[16];
|
||||
|
||||
array[i + 4] = new char[16];
|
||||
array2[i + 4] = new char[16];
|
||||
|
||||
array[i + 5] = new short[16];
|
||||
array2[i + 5] = new short[16];
|
||||
|
||||
array[i + 6] = new float[16];
|
||||
array2[i + 6] = new float[16];
|
||||
|
||||
array[i + 7] = new long[16];
|
||||
array2[i + 7] = new long[16];
|
||||
|
||||
array[i + 8] = new int[16];
|
||||
array2[i + 8] = new int[16];
|
||||
|
||||
array[i + 9] = new double[16];
|
||||
array2[i + 9] = new double[16];
|
||||
|
||||
// Subarray types are concrete objects.
|
||||
array[i + 10] = new16ElementArray(String.class, String.class);
|
||||
array2[i + 10] = new16ElementArray(String.class, String.class);
|
||||
|
||||
array[i + 11] = new16ElementArray(Integer.class, Integer.class);
|
||||
array2[i + 11] = new16ElementArray(Integer.class, Integer.class);
|
||||
|
||||
// Subarray types is an interface.
|
||||
array[i + 12] = new16ElementArray(CharSequence.class, String.class);
|
||||
array2[i + 12] = new16ElementArray(CharSequence.class, String.class);
|
||||
|
||||
array[i + 13] = null;
|
||||
array2[i + 13] = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark public void deepHashCode(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
Arrays.deepHashCode(array);
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark public void deepEquals(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
Arrays.deepEquals(array, array2);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Object[] new16ElementObjectarray() {
|
||||
Object[] array = new Object[16];
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
array[i] = new IntWrapper(i);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final <T, V> T[] new16ElementArray(Class<T> arrayType, Class<V> type)
|
||||
throws Exception {
|
||||
T[] array = (T []) Array.newInstance(type, 16);
|
||||
if (!arrayType.isAssignableFrom(type)) {
|
||||
throw new IllegalArgumentException(arrayType + " is not assignable from " + type);
|
||||
}
|
||||
|
||||
Constructor<V> constructor = type.getDeclaredConstructor(String.class);
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
array[i] = (T) constructor.newInstance(String.valueOf(i + 1000));
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class that provides very basic equals() and hashCode() operations
|
||||
* and doesn't resort to memoization tricks like {@link java.lang.Integer}.
|
||||
*
|
||||
* Useful for providing equal objects that aren't the same (a.equals(b) but
|
||||
* a != b).
|
||||
*/
|
||||
public static final class IntWrapper {
|
||||
private final int wrapped;
|
||||
|
||||
public IntWrapper(int wrap) {
|
||||
wrapped = wrap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof IntWrapper)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((IntWrapper) o).wrapped == this.wrapped;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/**
|
||||
* What does field access cost?
|
||||
*/
|
||||
public class FieldAccessBenchmark {
|
||||
private static class Inner {
|
||||
public int publicInnerIntVal;
|
||||
protected int protectedInnerIntVal;
|
||||
private int privateInnerIntVal;
|
||||
int packageInnerIntVal;
|
||||
}
|
||||
int intVal = 42;
|
||||
final int finalIntVal = 42;
|
||||
static int staticIntVal = 42;
|
||||
static final int staticFinalIntVal = 42;
|
||||
public int timeField(int reps) {
|
||||
int result = 0;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = intVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeFieldFinal(int reps) {
|
||||
int result = 0;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = finalIntVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeFieldStatic(int reps) {
|
||||
int result = 0;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = staticIntVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeFieldStaticFinal(int reps) {
|
||||
int result = 0;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = staticFinalIntVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeFieldCached(int reps) {
|
||||
int result = 0;
|
||||
int cachedIntVal = this.intVal;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = cachedIntVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeFieldPrivateInnerClassPublicField(int reps) {
|
||||
int result = 0;
|
||||
Inner inner = new Inner();
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = inner.publicInnerIntVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeFieldPrivateInnerClassProtectedField(int reps) {
|
||||
int result = 0;
|
||||
Inner inner = new Inner();
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = inner.protectedInnerIntVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeFieldPrivateInnerClassPrivateField(int reps) {
|
||||
int result = 0;
|
||||
Inner inner = new Inner();
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = inner.privateInnerIntVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeFieldPrivateInnerClassPackageField(int reps) {
|
||||
int result = 0;
|
||||
Inner inner = new Inner();
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = inner.packageInnerIntVal;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/**
|
||||
* A trivial class used by several benchmarks.
|
||||
*/
|
||||
public class Foo {
|
||||
int mSplat;
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import java.security.AccessController;
|
||||
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
/**
|
||||
* Compares performance of accessing system properties via
|
||||
* legacy security code
|
||||
* {@code AccessController.doPrivileged(new GetPropertyAction(key[, default]))}
|
||||
* vs. direct invocation of {@code System.getProperty(key[, default])}.
|
||||
*
|
||||
* As of 2018-07, libcore carries some patches to perform such short-circuiting,
|
||||
* so it's interesting to know how much better it performs.
|
||||
*/
|
||||
public class GetSystemPropertyBenchmark {
|
||||
|
||||
public void timeSystem_getProperty_default(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
System.getProperty("user.language", "en");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSystem_getProperty(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
System.getProperty("user.region");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeAccessController_getPropertyAction(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
AccessController.doPrivileged(
|
||||
new GetPropertyAction("user.language", "en"));
|
||||
}
|
||||
}
|
||||
|
||||
public void timeAccessController_getPropertyAction_default(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
AccessController.doPrivileged(
|
||||
new GetPropertyAction("user.region"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* How do the various hash maps compare?
|
||||
*/
|
||||
public class HashedCollectionsBenchmark {
|
||||
public void timeHashMapGet(int reps) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("hello", "world");
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
map.get("hello");
|
||||
}
|
||||
}
|
||||
public void timeHashMapGet_Synchronized(int reps) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
synchronized (map) {
|
||||
map.put("hello", "world");
|
||||
}
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
synchronized (map) {
|
||||
map.get("hello");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void timeHashtableGet(int reps) {
|
||||
Hashtable<String, String> map = new Hashtable<String, String>();
|
||||
map.put("hello", "world");
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
map.get("hello");
|
||||
}
|
||||
}
|
||||
public void timeLinkedHashMapGet(int reps) {
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
||||
map.put("hello", "world");
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
map.get("hello");
|
||||
}
|
||||
}
|
||||
public void timeConcurrentHashMapGet(int reps) {
|
||||
ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>();
|
||||
map.put("hello", "world");
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
map.get("hello");
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,103 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright 2016 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
import sys
|
||||
|
||||
max_conflict_depth = 20 # In practice does not go above 20 for reasonable IMT sizes
|
||||
try:
|
||||
imt_size = int(sys.argv[1])
|
||||
except (IndexError, ValueError):
|
||||
print("Usage: python ImtConflictBenchmarkGen.py <IMT_SIZE>")
|
||||
sys.exit(1)
|
||||
|
||||
license = """\
|
||||
/*
|
||||
* Copyright 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
"""
|
||||
description = """
|
||||
/**
|
||||
* This file is script-generated by ImtConflictBenchmarkGen.py.
|
||||
* It measures the performance impact of conflicts in interface method tables.
|
||||
* Run `python ImtConflictBenchmarkGen.py > ImtConflictBenchmark.java` to regenerate.
|
||||
*
|
||||
* Each interface has 64 methods, which is the current size of an IMT. C0 implements
|
||||
* one interface, C1 implements two, C2 implements three, and so on. The intent
|
||||
* is that C0 has no conflicts in its IMT, C1 has depth-2 conflicts in
|
||||
* its IMT, C2 has depth-3 conflicts, etc. This is currently guaranteed by
|
||||
* the fact that we hash interface methods by taking their method index modulo 64.
|
||||
* (Note that a "conflict depth" of 1 means no conflict at all.)
|
||||
*/\
|
||||
"""
|
||||
|
||||
print(license)
|
||||
print("package benchmarks;")
|
||||
print("import com.google.caliper.BeforeExperiment;")
|
||||
print(description)
|
||||
|
||||
print("public class ImtConflictBenchmark {")
|
||||
|
||||
# Warm up interface method tables
|
||||
print(" @BeforeExperiment")
|
||||
print(" public void setup() {")
|
||||
for i in range(max_conflict_depth):
|
||||
print(" C{0} c{0} = new C{0}();".format(i))
|
||||
for j in range(i+1):
|
||||
print(" callF{}(c{});".format(imt_size * j, i))
|
||||
print(" }")
|
||||
|
||||
# Print test cases--one for each conflict depth
|
||||
for i in range(max_conflict_depth):
|
||||
print(" public void timeConflictDepth{:02d}(int nreps) {{".format(i+1))
|
||||
print(" C{0} c{0} = new C{0}();".format(i))
|
||||
print(" for (int i = 0; i < nreps; i++) {")
|
||||
# Cycle through each interface method in an IMT entry in order
|
||||
# to test all conflict resolution possibilities
|
||||
for j in range(max_conflict_depth):
|
||||
print(" callF{}(c{});".format(imt_size * (j % (i + 1)), i))
|
||||
print(" }")
|
||||
print(" }")
|
||||
|
||||
# Make calls through the IMTs
|
||||
for i in range(max_conflict_depth):
|
||||
print(" public void callF{0}(I{1} i) {{ i.f{0}(); }}".format(imt_size*i, i))
|
||||
|
||||
# Class definitions, implementing varying amounts of interfaces
|
||||
for i in range(max_conflict_depth):
|
||||
interfaces = ", ".join(["I{}".format(j) for j in range(i+1)])
|
||||
print(" static class C{} implements {} {{}}".format(i, interfaces))
|
||||
|
||||
# Interface definitions, each with enough methods to fill an entire IMT
|
||||
for i in range(max_conflict_depth):
|
||||
print(" static interface I{} {{".format(i))
|
||||
for j in range(imt_size):
|
||||
print(" default void f{}() {{}}".format(i*imt_size + j))
|
||||
print(" }")
|
||||
|
||||
print("}")
|
|
@ -0,0 +1,641 @@
|
|||
/*
|
||||
* Copyright 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
public class InvokeInterface {
|
||||
static MultiClass multi;
|
||||
|
||||
static {
|
||||
multi = new MultiClass();
|
||||
}
|
||||
|
||||
public void timeCall0Concrete(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall0Concrete(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall0Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall0Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall1Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall1Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall2Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall2Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall3Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall3Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall4Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall4Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall5Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall5Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall6Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall6Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall7Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall7Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall8Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall8Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall9Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall9Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall10Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall10Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall11Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall11Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall12Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall12Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall13Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall13Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall14Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall14Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall15Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall15Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall16Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall16Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall17Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall17Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall18Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall18Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall19Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall19Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall20Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall20Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall21Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall21Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall22Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall22Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall23Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall23Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall24Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall24Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall25Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall25Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall26Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall26Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall27Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall27Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall28Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall28Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall29Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall29Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall30Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall30Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall31Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall31Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall32Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall32Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall33Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall33Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall34Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall34Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall35Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall35Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall36Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall36Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall37Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall37Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall38Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall38Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall39Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall39Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall40Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall40Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall41Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall41Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall42Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall42Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall43Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall43Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall44Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall44Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall45Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall45Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall46Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall46Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall47Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall47Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall48Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall48Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall49Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall49Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall50Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall50Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall51Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall51Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall52Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall52Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall53Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall53Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall54Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall54Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall55Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall55Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall56Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall56Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall57Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall57Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall58Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall58Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall59Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall59Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall60Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall60Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall61Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall61Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall62Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall62Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall63Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall63Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCall64Interface(int nreps) {
|
||||
MultiClass m = multi;
|
||||
for (int i = 0; i < nreps; i++) {
|
||||
doCall64Interface(m);
|
||||
}
|
||||
}
|
||||
|
||||
// Try calling these through the IMT/IfTable
|
||||
public void doCall0Interface(Iface0 i) { i.callIface0(); }
|
||||
public void doCall1Interface(Iface1 i) { i.callIface1(); }
|
||||
public void doCall2Interface(Iface2 i) { i.callIface2(); }
|
||||
public void doCall3Interface(Iface3 i) { i.callIface3(); }
|
||||
public void doCall4Interface(Iface4 i) { i.callIface4(); }
|
||||
public void doCall5Interface(Iface5 i) { i.callIface5(); }
|
||||
public void doCall6Interface(Iface6 i) { i.callIface6(); }
|
||||
public void doCall7Interface(Iface7 i) { i.callIface7(); }
|
||||
public void doCall8Interface(Iface8 i) { i.callIface8(); }
|
||||
public void doCall9Interface(Iface9 i) { i.callIface9(); }
|
||||
public void doCall10Interface(Iface10 i) { i.callIface10(); }
|
||||
public void doCall11Interface(Iface11 i) { i.callIface11(); }
|
||||
public void doCall12Interface(Iface12 i) { i.callIface12(); }
|
||||
public void doCall13Interface(Iface13 i) { i.callIface13(); }
|
||||
public void doCall14Interface(Iface14 i) { i.callIface14(); }
|
||||
public void doCall15Interface(Iface15 i) { i.callIface15(); }
|
||||
public void doCall16Interface(Iface16 i) { i.callIface16(); }
|
||||
public void doCall17Interface(Iface17 i) { i.callIface17(); }
|
||||
public void doCall18Interface(Iface18 i) { i.callIface18(); }
|
||||
public void doCall19Interface(Iface19 i) { i.callIface19(); }
|
||||
public void doCall20Interface(Iface20 i) { i.callIface20(); }
|
||||
public void doCall21Interface(Iface21 i) { i.callIface21(); }
|
||||
public void doCall22Interface(Iface22 i) { i.callIface22(); }
|
||||
public void doCall23Interface(Iface23 i) { i.callIface23(); }
|
||||
public void doCall24Interface(Iface24 i) { i.callIface24(); }
|
||||
public void doCall25Interface(Iface25 i) { i.callIface25(); }
|
||||
public void doCall26Interface(Iface26 i) { i.callIface26(); }
|
||||
public void doCall27Interface(Iface27 i) { i.callIface27(); }
|
||||
public void doCall28Interface(Iface28 i) { i.callIface28(); }
|
||||
public void doCall29Interface(Iface29 i) { i.callIface29(); }
|
||||
public void doCall30Interface(Iface30 i) { i.callIface30(); }
|
||||
public void doCall31Interface(Iface31 i) { i.callIface31(); }
|
||||
public void doCall32Interface(Iface32 i) { i.callIface32(); }
|
||||
public void doCall33Interface(Iface33 i) { i.callIface33(); }
|
||||
public void doCall34Interface(Iface34 i) { i.callIface34(); }
|
||||
public void doCall35Interface(Iface35 i) { i.callIface35(); }
|
||||
public void doCall36Interface(Iface36 i) { i.callIface36(); }
|
||||
public void doCall37Interface(Iface37 i) { i.callIface37(); }
|
||||
public void doCall38Interface(Iface38 i) { i.callIface38(); }
|
||||
public void doCall39Interface(Iface39 i) { i.callIface39(); }
|
||||
public void doCall40Interface(Iface40 i) { i.callIface40(); }
|
||||
public void doCall41Interface(Iface41 i) { i.callIface41(); }
|
||||
public void doCall42Interface(Iface42 i) { i.callIface42(); }
|
||||
public void doCall43Interface(Iface43 i) { i.callIface43(); }
|
||||
public void doCall44Interface(Iface44 i) { i.callIface44(); }
|
||||
public void doCall45Interface(Iface45 i) { i.callIface45(); }
|
||||
public void doCall46Interface(Iface46 i) { i.callIface46(); }
|
||||
public void doCall47Interface(Iface47 i) { i.callIface47(); }
|
||||
public void doCall48Interface(Iface48 i) { i.callIface48(); }
|
||||
public void doCall49Interface(Iface49 i) { i.callIface49(); }
|
||||
public void doCall50Interface(Iface50 i) { i.callIface50(); }
|
||||
public void doCall51Interface(Iface51 i) { i.callIface51(); }
|
||||
public void doCall52Interface(Iface52 i) { i.callIface52(); }
|
||||
public void doCall53Interface(Iface53 i) { i.callIface53(); }
|
||||
public void doCall54Interface(Iface54 i) { i.callIface54(); }
|
||||
public void doCall55Interface(Iface55 i) { i.callIface55(); }
|
||||
public void doCall56Interface(Iface56 i) { i.callIface56(); }
|
||||
public void doCall57Interface(Iface57 i) { i.callIface57(); }
|
||||
public void doCall58Interface(Iface58 i) { i.callIface58(); }
|
||||
public void doCall59Interface(Iface59 i) { i.callIface59(); }
|
||||
public void doCall60Interface(Iface60 i) { i.callIface60(); }
|
||||
public void doCall61Interface(Iface61 i) { i.callIface61(); }
|
||||
public void doCall62Interface(Iface62 i) { i.callIface62(); }
|
||||
public void doCall63Interface(Iface63 i) { i.callIface63(); }
|
||||
public void doCall64Interface(Iface64 i) { i.callIface64(); }
|
||||
|
||||
// Try calling this through the vtable for comparison.
|
||||
public void doCall0Concrete(MultiClass m) { m.callIface0(); }
|
||||
|
||||
// IMTs are 64 entries in length. By making this 65 interfaces we guarantee that we will have a
|
||||
// collision.
|
||||
static class MultiClass implements Iface0, Iface1, Iface2, Iface3, Iface4,
|
||||
Iface5, Iface6, Iface7, Iface8, Iface9,
|
||||
Iface10, Iface11, Iface12, Iface13, Iface14,
|
||||
Iface15, Iface16, Iface17, Iface18, Iface19,
|
||||
Iface20, Iface21, Iface22, Iface23, Iface24,
|
||||
Iface25, Iface26, Iface27, Iface28, Iface29,
|
||||
Iface30, Iface31, Iface32, Iface33, Iface34,
|
||||
Iface35, Iface36, Iface37, Iface38, Iface39,
|
||||
Iface40, Iface41, Iface42, Iface43, Iface44,
|
||||
Iface45, Iface46, Iface47, Iface48, Iface49,
|
||||
Iface50, Iface51, Iface52, Iface53, Iface54,
|
||||
Iface55, Iface56, Iface57, Iface58, Iface59,
|
||||
Iface60, Iface61, Iface62, Iface63, Iface64 { }
|
||||
|
||||
// The declaration of the 64 interfaces. We give them all default methods to avoid having to
|
||||
// repeat ourselves.
|
||||
static interface Iface0 { default void callIface0() {} }
|
||||
static interface Iface1 { default void callIface1() {} }
|
||||
static interface Iface2 { default void callIface2() {} }
|
||||
static interface Iface3 { default void callIface3() {} }
|
||||
static interface Iface4 { default void callIface4() {} }
|
||||
static interface Iface5 { default void callIface5() {} }
|
||||
static interface Iface6 { default void callIface6() {} }
|
||||
static interface Iface7 { default void callIface7() {} }
|
||||
static interface Iface8 { default void callIface8() {} }
|
||||
static interface Iface9 { default void callIface9() {} }
|
||||
static interface Iface10 { default void callIface10() {} }
|
||||
static interface Iface11 { default void callIface11() {} }
|
||||
static interface Iface12 { default void callIface12() {} }
|
||||
static interface Iface13 { default void callIface13() {} }
|
||||
static interface Iface14 { default void callIface14() {} }
|
||||
static interface Iface15 { default void callIface15() {} }
|
||||
static interface Iface16 { default void callIface16() {} }
|
||||
static interface Iface17 { default void callIface17() {} }
|
||||
static interface Iface18 { default void callIface18() {} }
|
||||
static interface Iface19 { default void callIface19() {} }
|
||||
static interface Iface20 { default void callIface20() {} }
|
||||
static interface Iface21 { default void callIface21() {} }
|
||||
static interface Iface22 { default void callIface22() {} }
|
||||
static interface Iface23 { default void callIface23() {} }
|
||||
static interface Iface24 { default void callIface24() {} }
|
||||
static interface Iface25 { default void callIface25() {} }
|
||||
static interface Iface26 { default void callIface26() {} }
|
||||
static interface Iface27 { default void callIface27() {} }
|
||||
static interface Iface28 { default void callIface28() {} }
|
||||
static interface Iface29 { default void callIface29() {} }
|
||||
static interface Iface30 { default void callIface30() {} }
|
||||
static interface Iface31 { default void callIface31() {} }
|
||||
static interface Iface32 { default void callIface32() {} }
|
||||
static interface Iface33 { default void callIface33() {} }
|
||||
static interface Iface34 { default void callIface34() {} }
|
||||
static interface Iface35 { default void callIface35() {} }
|
||||
static interface Iface36 { default void callIface36() {} }
|
||||
static interface Iface37 { default void callIface37() {} }
|
||||
static interface Iface38 { default void callIface38() {} }
|
||||
static interface Iface39 { default void callIface39() {} }
|
||||
static interface Iface40 { default void callIface40() {} }
|
||||
static interface Iface41 { default void callIface41() {} }
|
||||
static interface Iface42 { default void callIface42() {} }
|
||||
static interface Iface43 { default void callIface43() {} }
|
||||
static interface Iface44 { default void callIface44() {} }
|
||||
static interface Iface45 { default void callIface45() {} }
|
||||
static interface Iface46 { default void callIface46() {} }
|
||||
static interface Iface47 { default void callIface47() {} }
|
||||
static interface Iface48 { default void callIface48() {} }
|
||||
static interface Iface49 { default void callIface49() {} }
|
||||
static interface Iface50 { default void callIface50() {} }
|
||||
static interface Iface51 { default void callIface51() {} }
|
||||
static interface Iface52 { default void callIface52() {} }
|
||||
static interface Iface53 { default void callIface53() {} }
|
||||
static interface Iface54 { default void callIface54() {} }
|
||||
static interface Iface55 { default void callIface55() {} }
|
||||
static interface Iface56 { default void callIface56() {} }
|
||||
static interface Iface57 { default void callIface57() {} }
|
||||
static interface Iface58 { default void callIface58() {} }
|
||||
static interface Iface59 { default void callIface59() {} }
|
||||
static interface Iface60 { default void callIface60() {} }
|
||||
static interface Iface61 { default void callIface61() {} }
|
||||
static interface Iface62 { default void callIface62() {} }
|
||||
static interface Iface63 { default void callIface63() {} }
|
||||
static interface Iface64 { default void callIface64() {} }
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Benchmark;
|
||||
import java.util.Locale;
|
||||
import libcore.icu.LocaleData;
|
||||
|
||||
public final class LocaleDataBenchmark {
|
||||
private static final Locale[] TEST_LOCALES = new Locale[] {
|
||||
Locale.forLanguageTag("en-US"),
|
||||
Locale.forLanguageTag("jp-JP"),
|
||||
Locale.forLanguageTag("es-419"),
|
||||
Locale.forLanguageTag("ar-EG"),
|
||||
Locale.forLanguageTag("zh-CN"),
|
||||
};
|
||||
|
||||
public void timeInitLocaleData(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (Locale locale : TEST_LOCALES) {
|
||||
LocaleData.initLocaleData(locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/**
|
||||
* Compares various kinds of method invocation.
|
||||
*/
|
||||
public class MethodInvocationBenchmark {
|
||||
interface I {
|
||||
void emptyInterface();
|
||||
}
|
||||
|
||||
static class C implements I {
|
||||
private int field;
|
||||
|
||||
private int getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public int timeInternalGetter(int reps) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result = getField();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int timeInternalFieldAccess(int reps) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result = field;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void emptyStatic() {
|
||||
}
|
||||
|
||||
public void emptyVirtual() {
|
||||
}
|
||||
|
||||
public void emptyInterface() {
|
||||
}
|
||||
}
|
||||
|
||||
public void timeInternalGetter(int reps) {
|
||||
new C().timeInternalGetter(reps);
|
||||
}
|
||||
|
||||
public void timeInternalFieldAccess(int reps) {
|
||||
new C().timeInternalFieldAccess(reps);
|
||||
}
|
||||
|
||||
// Test an intrinsic.
|
||||
public int timeStringLength(int reps) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result = "hello, world!".length();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void timeEmptyStatic(int reps) {
|
||||
C c = new C();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
c.emptyStatic();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeEmptyVirtual(int reps) {
|
||||
C c = new C();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
c.emptyVirtual();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeEmptyInterface(int reps) {
|
||||
I c = new C();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
c.emptyInterface();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Inner {
|
||||
private int i;
|
||||
private void privateMethod() { ++i; }
|
||||
protected void protectedMethod() { ++i; }
|
||||
public void publicMethod() { ++i; }
|
||||
void packageMethod() { ++i; }
|
||||
final void finalPackageMethod() { ++i; }
|
||||
}
|
||||
|
||||
public void timePrivateInnerPublicMethod(int reps) {
|
||||
Inner inner = new Inner();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
inner.publicMethod();
|
||||
}
|
||||
}
|
||||
|
||||
public void timePrivateInnerProtectedMethod(int reps) {
|
||||
Inner inner = new Inner();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
inner.protectedMethod();
|
||||
}
|
||||
}
|
||||
|
||||
public void timePrivateInnerPrivateMethod(int reps) {
|
||||
Inner inner = new Inner();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
inner.privateMethod();
|
||||
}
|
||||
}
|
||||
|
||||
public void timePrivateInnerPackageMethod(int reps) {
|
||||
Inner inner = new Inner();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
inner.packageMethod();
|
||||
}
|
||||
}
|
||||
|
||||
public void timePrivateInnerFinalPackageMethod(int reps) {
|
||||
Inner inner = new Inner();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
inner.finalPackageMethod();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/**
|
||||
* How much do various kinds of multiplication cost?
|
||||
*/
|
||||
public class MultiplicationBenchmark {
|
||||
public int timeMultiplyIntByConstant10(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= 10;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByConstant8(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= 8;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByVariable10(int reps) {
|
||||
int result = 1;
|
||||
int factor = 10;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= factor;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByVariable8(int reps) {
|
||||
int result = 1;
|
||||
int factor = 8;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= factor;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import java.lang.ref.PhantomReference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Benchmark to evaluate the performance of References.
|
||||
*/
|
||||
public class ReferenceBenchmark {
|
||||
|
||||
private Object object;
|
||||
|
||||
// How fast can references can be allocated?
|
||||
public void timeAlloc(int reps) {
|
||||
ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
|
||||
for (int i = 0; i < reps; i++) {
|
||||
new PhantomReference(object, queue);
|
||||
}
|
||||
}
|
||||
|
||||
// How fast can references can be allocated and manually enqueued?
|
||||
public void timeAllocAndEnqueue(int reps) {
|
||||
ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
|
||||
for (int i = 0; i < reps; i++) {
|
||||
(new PhantomReference<Object>(object, queue)).enqueue();
|
||||
}
|
||||
}
|
||||
|
||||
// How fast can references can be allocated, enqueued, and polled?
|
||||
public void timeAllocEnqueueAndPoll(int reps) {
|
||||
ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
|
||||
for (int i = 0; i < reps; i++) {
|
||||
(new PhantomReference<Object>(object, queue)).enqueue();
|
||||
}
|
||||
for (int i = 0; i < reps; i++) {
|
||||
queue.poll();
|
||||
}
|
||||
}
|
||||
|
||||
// How fast can references can be allocated, enqueued, and removed?
|
||||
public void timeAllocEnqueueAndRemove(int reps) {
|
||||
ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
|
||||
for (int i = 0; i < reps; i++) {
|
||||
(new PhantomReference<Object>(object, queue)).enqueue();
|
||||
}
|
||||
for (int i = 0; i < reps; i++) {
|
||||
try {
|
||||
queue.remove();
|
||||
} catch (InterruptedException ie) {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// How fast can references can be implicitly allocated, enqueued, and
|
||||
// removed?
|
||||
public void timeAllocImplicitEnqueueAndRemove(int reps) {
|
||||
ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
|
||||
List<Object> refs = new ArrayList<Object>();
|
||||
for (int i = 0; i < reps; i++) {
|
||||
refs.add(new PhantomReference<Object>(new Object(), queue));
|
||||
}
|
||||
Runtime.getRuntime().gc();
|
||||
for (int i = 0; i < reps; i++) {
|
||||
try {
|
||||
queue.remove();
|
||||
} catch (InterruptedException ie) {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static private class FinalizableObject {
|
||||
AtomicInteger count;
|
||||
|
||||
public FinalizableObject(AtomicInteger count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() {
|
||||
count.incrementAndGet();
|
||||
}
|
||||
}
|
||||
|
||||
// How fast does finalization run?
|
||||
public void timeFinalization(int reps) {
|
||||
// Allocate a bunch of finalizable objects.
|
||||
int n = reps;
|
||||
AtomicInteger count = new AtomicInteger(0);
|
||||
for (int i = 0; i < n; i++) {
|
||||
new FinalizableObject(count);
|
||||
}
|
||||
|
||||
// Run GC so the objects will be collected for finalization.
|
||||
Runtime.getRuntime().gc();
|
||||
|
||||
// Wait for finalization.
|
||||
Runtime.getRuntime().runFinalization();
|
||||
|
||||
// Double check all the objects were finalized.
|
||||
int got = count.get();
|
||||
if (n != got) {
|
||||
throw new IllegalStateException(
|
||||
String.format("Only %i of %i objects finalized?", got, n));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class ReferenceGetBenchmark {
|
||||
@Param boolean intrinsicDisabled;
|
||||
|
||||
private Object obj = "str";
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
Field intrinsicDisabledField = Reference.class.getDeclaredField("disableIntrinsic");
|
||||
intrinsicDisabledField.setAccessible(true);
|
||||
intrinsicDisabledField.setBoolean(null, intrinsicDisabled);
|
||||
}
|
||||
|
||||
public void timeSoftReferenceGet(int reps) throws Exception {
|
||||
Reference soft = new SoftReference(obj);
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Object o = soft.get();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeWeakReferenceGet(int reps) throws Exception {
|
||||
Reference weak = new WeakReference(obj);
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Object o = weak.get();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeNonPreservedWeakReferenceGet(int reps) throws Exception {
|
||||
Reference weak = new WeakReference(obj);
|
||||
obj = null;
|
||||
Runtime.getRuntime().gc();
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Object o = weak.get();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* This measures performance of operations on small BigIntegers.
|
||||
* We manually determine the number of iterations so that it should cause total memory
|
||||
* allocation on the order of a few hundred megabytes. Due to BigInteger's reliance on
|
||||
* finalization, these may unfortunately all be kept around at once.
|
||||
*
|
||||
* This is not structured as a proper benchmark; just run main(), e.g. with
|
||||
* vogar libcore/benchmarks/src/benchmarks/SmallBigIntegerBenchmark.java
|
||||
*/
|
||||
public class SmallBigIntegerBenchmark {
|
||||
// We allocate about 2 1/3 BigIntegers per iteration.
|
||||
// Assuming 100 bytes/BigInteger, this gives us around 500MB total.
|
||||
static final int NITERS = 2 * 1000 * 1000;
|
||||
static final BigInteger BIG_THREE = BigInteger.valueOf(3);
|
||||
static final BigInteger BIG_FOUR = BigInteger.valueOf(4);
|
||||
|
||||
public static void main(String args[]) {
|
||||
final Random r = new Random();
|
||||
BigInteger x = new BigInteger(20, r);
|
||||
final long startNanos = System.nanoTime();
|
||||
long intermediateNanos = 0;
|
||||
for (int i = 0; i < NITERS; ++i) {
|
||||
if (i == NITERS / 100) {
|
||||
intermediateNanos = System.nanoTime();
|
||||
}
|
||||
// We know this converges, but the compiler doesn't.
|
||||
if (x.and(BigInteger.ONE).equals(BigInteger.ONE)) {
|
||||
x = x.multiply(BIG_THREE).add(BigInteger.ONE);
|
||||
} else {
|
||||
x = x.shiftRight(1);
|
||||
}
|
||||
}
|
||||
if (x.signum() < 0 || x.compareTo(BIG_FOUR) > 0) {
|
||||
throw new AssertionError("Something went horribly wrong.");
|
||||
}
|
||||
final long finalNanos = System.nanoTime();
|
||||
double firstFewTime = ((double) intermediateNanos - (double) startNanos) / (NITERS / 100);
|
||||
double restTime = ((double) finalNanos - (double) intermediateNanos) / (99 * NITERS / 100);
|
||||
System.out.println("First Few: " + firstFewTime
|
||||
+ " nanoseconds per iteration (2.33 BigInteger ops/iter)");
|
||||
System.out.println("Remainder: " + restTime + " nanoseconds per iteration");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2016 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/**
|
||||
* How long does it take to access a string in the dex cache?
|
||||
*/
|
||||
public class StringDexCacheBenchmark {
|
||||
public int timeStringDexCacheAccess(int reps) {
|
||||
int v = 0;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
// Deliberately obscured to make optimizations less likely.
|
||||
String s = (rep >= 0) ? "hello, world!" : null;
|
||||
v += s.length();
|
||||
}
|
||||
return v;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
/**
|
||||
* How do the various schemes for iterating through a string compare?
|
||||
*/
|
||||
public class StringIterationBenchmark {
|
||||
public void timeStringIteration0(int reps) {
|
||||
String s = "hello, world!";
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
char ch;
|
||||
for (int i = 0; i < s.length(); ++i) {
|
||||
ch = s.charAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void timeStringIteration1(int reps) {
|
||||
String s = "hello, world!";
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
char ch;
|
||||
for (int i = 0, length = s.length(); i < length; ++i) {
|
||||
ch = s.charAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void timeStringIteration2(int reps) {
|
||||
String s = "hello, world!";
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
char ch;
|
||||
char[] chars = s.toCharArray();
|
||||
for (int i = 0, length = chars.length; i < length; ++i) {
|
||||
ch = chars[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
public void timeStringToCharArray(int reps) {
|
||||
String s = "hello, world!";
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
char[] chars = s.toCharArray();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (C) 2013 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
|
||||
public class SystemArrayCopyBenchmark {
|
||||
@Param({"2", "4", "8", "16", "32", "64", "128", "256", "512", "1024",
|
||||
"2048", "4096", "8192", "16384", "32768", "65536", "131072", "262144"})
|
||||
int arrayLength;
|
||||
|
||||
// Provides benchmarking for different types of arrays using the arraycopy function.
|
||||
|
||||
public void timeSystemCharArrayCopy(int reps) {
|
||||
final int len = arrayLength;
|
||||
char[] src = new char[len];
|
||||
char[] dst = new char[len];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
System.arraycopy(src, 0, dst, 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSystemByteArrayCopy(int reps) {
|
||||
final int len = arrayLength;
|
||||
byte[] src = new byte[len];
|
||||
byte[] dst = new byte[len];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
System.arraycopy(src, 0, dst, 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSystemShortArrayCopy(int reps) {
|
||||
final int len = arrayLength;
|
||||
short[] src = new short[len];
|
||||
short[] dst = new short[len];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
System.arraycopy(src, 0, dst, 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSystemIntArrayCopy(int reps) {
|
||||
final int len = arrayLength;
|
||||
int[] src = new int[len];
|
||||
int[] dst = new int[len];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
System.arraycopy(src, 0, dst, 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSystemLongArrayCopy(int reps) {
|
||||
final int len = arrayLength;
|
||||
long[] src = new long[len];
|
||||
long[] dst = new long[len];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
System.arraycopy(src, 0, dst, 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSystemFloatArrayCopy(int reps) {
|
||||
final int len = arrayLength;
|
||||
float[] src = new float[len];
|
||||
float[] dst = new float[len];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
System.arraycopy(src, 0, dst, 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSystemDoubleArrayCopy(int reps) {
|
||||
final int len = arrayLength;
|
||||
double[] src = new double[len];
|
||||
double[] dst = new double[len];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
System.arraycopy(src, 0, dst, 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSystemBooleanArrayCopy(int reps) {
|
||||
final int len = arrayLength;
|
||||
boolean[] src = new boolean[len];
|
||||
boolean[] dst = new boolean[len];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
System.arraycopy(src, 0, dst, 0, len);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Is there a performance reason to "Prefer virtual over interface", as the
|
||||
* Android documentation once claimed?
|
||||
*/
|
||||
public class VirtualVersusInterfaceBenchmark {
|
||||
public void timeMapPut(int reps) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
map.put("hello", "world");
|
||||
}
|
||||
}
|
||||
public void timeHashMapPut(int reps) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
map.put("hello", "world");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Param;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class XmlParseBenchmark {
|
||||
|
||||
@Param String xmlFile;
|
||||
ByteArrayInputStream inputStream;
|
||||
|
||||
static List<String> xmlFileValues = Arrays.asList(
|
||||
"/etc/apns-conf.xml",
|
||||
"/etc/media_profiles.xml",
|
||||
"/etc/permissions/features.xml"
|
||||
);
|
||||
|
||||
private SAXParser saxParser;
|
||||
private DocumentBuilder documentBuilder;
|
||||
private Constructor<? extends XmlPullParser> kxmlConstructor;
|
||||
private Constructor<? extends XmlPullParser> expatConstructor;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
byte[] xmlBytes = getXmlBytes();
|
||||
inputStream = new ByteArrayInputStream(xmlBytes);
|
||||
inputStream.mark(xmlBytes.length);
|
||||
|
||||
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
|
||||
saxParser = saxParserFactory.newSAXParser();
|
||||
|
||||
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilder = builderFactory.newDocumentBuilder();
|
||||
|
||||
kxmlConstructor = (Constructor) Class.forName("com.android.org.kxml2.io.KXmlParser")
|
||||
.getConstructor();
|
||||
expatConstructor = (Constructor) Class.forName("org.apache.harmony.xml.ExpatPullParser")
|
||||
.getConstructor();
|
||||
}
|
||||
|
||||
private byte[] getXmlBytes() throws IOException {
|
||||
FileInputStream fileIn = new FileInputStream(xmlFile);
|
||||
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
|
||||
int count;
|
||||
byte[] buffer = new byte[1024];
|
||||
while ((count = fileIn.read(buffer)) != -1) {
|
||||
bytesOut.write(buffer, 0, count);
|
||||
}
|
||||
fileIn.close();
|
||||
return bytesOut.toByteArray();
|
||||
}
|
||||
|
||||
public int timeSax(int reps) throws IOException, SAXException {
|
||||
int elementCount = 0;
|
||||
for (int i = 0; i < reps; i++) {
|
||||
inputStream.reset();
|
||||
ElementCounterSaxHandler elementCounterSaxHandler = new ElementCounterSaxHandler();
|
||||
saxParser.parse(inputStream, elementCounterSaxHandler);
|
||||
elementCount += elementCounterSaxHandler.elementCount;
|
||||
}
|
||||
return elementCount;
|
||||
}
|
||||
|
||||
private static class ElementCounterSaxHandler extends DefaultHandler {
|
||||
int elementCount = 0;
|
||||
@Override public void startElement(String uri, String localName,
|
||||
String qName, Attributes attributes) {
|
||||
elementCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public int timeDom(int reps) throws IOException, SAXException {
|
||||
int elementCount = 0;
|
||||
for (int i = 0; i < reps; i++) {
|
||||
inputStream.reset();
|
||||
Document document = documentBuilder.parse(inputStream);
|
||||
elementCount += countDomElements(document.getDocumentElement());
|
||||
}
|
||||
return elementCount;
|
||||
}
|
||||
|
||||
private int countDomElements(Node node) {
|
||||
int result = 0;
|
||||
for (; node != null; node = node.getNextSibling()) {
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
result++;
|
||||
}
|
||||
result += countDomElements(node.getFirstChild());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int timeExpat(int reps) throws Exception {
|
||||
return testXmlPull(expatConstructor, reps);
|
||||
}
|
||||
|
||||
public int timeKxml(int reps) throws Exception {
|
||||
return testXmlPull(kxmlConstructor, reps);
|
||||
}
|
||||
|
||||
private int testXmlPull(Constructor<? extends XmlPullParser> constructor, int reps)
|
||||
throws Exception {
|
||||
int elementCount = 0;
|
||||
for (int i = 0; i < reps; i++) {
|
||||
inputStream.reset();
|
||||
XmlPullParser xmlPullParser = constructor.newInstance();
|
||||
xmlPullParser.setInput(inputStream, "UTF-8");
|
||||
int type;
|
||||
while ((type = xmlPullParser.next()) != XmlPullParser.END_DOCUMENT) {
|
||||
if (type == XmlPullParser.START_TAG) {
|
||||
elementCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return elementCount;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Param;
|
||||
import java.io.CharArrayWriter;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Random;
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
|
||||
|
||||
public class XmlSerializeBenchmark {
|
||||
|
||||
@Param( {"0.99 0.7 0.7 0.7 0.7 0.7",
|
||||
"0.999 0.3 0.3 0.95 0.9 0.9"})
|
||||
String datasetAsString;
|
||||
|
||||
@Param( { "854328", "312547"} )
|
||||
int seed;
|
||||
|
||||
double[] dataset;
|
||||
private Constructor<? extends XmlSerializer> kxmlConstructor;
|
||||
private Constructor<? extends XmlSerializer> fastConstructor;
|
||||
|
||||
private void serializeRandomXml(Constructor<? extends XmlSerializer> ctor, long seed)
|
||||
throws Exception {
|
||||
double contChance = dataset[0];
|
||||
double levelUpChance = dataset[1];
|
||||
double levelDownChance = dataset[2];
|
||||
double attributeChance = dataset[3];
|
||||
double writeChance1 = dataset[4];
|
||||
double writeChance2 = dataset[5];
|
||||
|
||||
XmlSerializer serializer = (XmlSerializer) ctor.newInstance();
|
||||
|
||||
CharArrayWriter w = new CharArrayWriter();
|
||||
serializer.setOutput(w);
|
||||
int level = 0;
|
||||
Random r = new Random(seed);
|
||||
char[] toWrite = {'a','b','c','d','s','z'};
|
||||
serializer.startDocument("UTF-8", true);
|
||||
while(r.nextDouble() < contChance) {
|
||||
while(level > 0 && r.nextDouble() < levelUpChance) {
|
||||
serializer.endTag("aaaaaa", "bbbbbb");
|
||||
level--;
|
||||
}
|
||||
while(r.nextDouble() < levelDownChance) {
|
||||
serializer.startTag("aaaaaa", "bbbbbb");
|
||||
level++;
|
||||
}
|
||||
serializer.startTag("aaaaaa", "bbbbbb");
|
||||
level++;
|
||||
while(r.nextDouble() < attributeChance) {
|
||||
serializer.attribute("aaaaaa", "cccccc", "dddddd");
|
||||
}
|
||||
serializer.endTag("aaaaaa", "bbbbbb");
|
||||
level--;
|
||||
while(r.nextDouble() < writeChance1)
|
||||
serializer.text(toWrite, 0, 5);
|
||||
while(r.nextDouble() < writeChance2)
|
||||
serializer.text("Textxtsxtxtxt ");
|
||||
}
|
||||
serializer.endDocument();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
kxmlConstructor = (Constructor) Class.forName("com.android.org.kxml2.io.KXmlSerializer")
|
||||
.getConstructor();
|
||||
fastConstructor = (Constructor) Class.forName("com.android.internal.util.FastXmlSerializer")
|
||||
.getConstructor();
|
||||
String[] splitted = datasetAsString.split(" ");
|
||||
dataset = new double[splitted.length];
|
||||
for (int i = 0; i < splitted.length; i++) {
|
||||
dataset[i] = Double.parseDouble(splitted[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void internalTimeSerializer(Constructor<? extends XmlSerializer> ctor, int reps)
|
||||
throws Exception {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
serializeRandomXml(ctor, seed);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeKxml(int reps) throws Exception {
|
||||
internalTimeSerializer(kxmlConstructor, reps);
|
||||
}
|
||||
|
||||
public void timeFast(int reps) throws Exception {
|
||||
internalTimeSerializer(fastConstructor, reps);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Param;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Random;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
|
||||
public class ZipFileBenchmark {
|
||||
|
||||
private File file;
|
||||
@Param({"128", "1024", "8192"}) int numEntries;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
System.setProperty("java.io.tmpdir", "/data/local/tmp");
|
||||
file = File.createTempFile(getClass().getName(), ".zip");
|
||||
file.deleteOnExit();
|
||||
writeEntries(new ZipOutputStream(new FileOutputStream(file)), numEntries, 0);
|
||||
ZipFile zipFile = new ZipFile(file);
|
||||
for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements(); ) {
|
||||
ZipEntry zipEntry = e.nextElement();
|
||||
}
|
||||
zipFile.close();
|
||||
}
|
||||
|
||||
public void timeZipFileOpen(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
ZipFile zf = new ZipFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compresses the given number of files, each of the given size, into a .zip archive.
|
||||
*/
|
||||
protected void writeEntries(ZipOutputStream out, int entryCount, long entrySize)
|
||||
throws IOException {
|
||||
byte[] writeBuffer = new byte[8192];
|
||||
Random random = new Random();
|
||||
try {
|
||||
for (int entry = 0; entry < entryCount; ++entry) {
|
||||
ZipEntry ze = new ZipEntry(Integer.toHexString(entry));
|
||||
ze.setSize(entrySize);
|
||||
out.putNextEntry(ze);
|
||||
|
||||
for (long i = 0; i < entrySize; i += writeBuffer.length) {
|
||||
random.nextBytes(writeBuffer);
|
||||
int byteCount = (int) Math.min(writeBuffer.length, entrySize - i);
|
||||
out.write(writeBuffer, 0, byteCount);
|
||||
}
|
||||
|
||||
out.closeEntry();
|
||||
}
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package benchmarks;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Param;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Random;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
|
||||
public class ZipFileReadBenchmark {
|
||||
private File file;
|
||||
@Param({"1024", "16384", "65536"}) int readBufferSize;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
System.setProperty("java.io.tmpdir", "/data/local/tmp");
|
||||
file = File.createTempFile(getClass().getName(), ".zip");
|
||||
writeEntries(new ZipOutputStream(new FileOutputStream(file)), 2, 1024*1024);
|
||||
ZipFile zipFile = new ZipFile(file);
|
||||
for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements(); ) {
|
||||
ZipEntry zipEntry = e.nextElement();
|
||||
}
|
||||
zipFile.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compresses the given number of files, each of the given size, into a .zip archive.
|
||||
*/
|
||||
protected void writeEntries(ZipOutputStream out, int entryCount, long entrySize)
|
||||
throws IOException {
|
||||
byte[] writeBuffer = new byte[8192];
|
||||
Random random = new Random();
|
||||
try {
|
||||
for (int entry = 0; entry < entryCount; ++entry) {
|
||||
ZipEntry ze = new ZipEntry(Integer.toHexString(entry));
|
||||
ze.setSize(entrySize);
|
||||
out.putNextEntry(ze);
|
||||
|
||||
for (long i = 0; i < entrySize; i += writeBuffer.length) {
|
||||
random.nextBytes(writeBuffer);
|
||||
int byteCount = (int) Math.min(writeBuffer.length, entrySize - i);
|
||||
out.write(writeBuffer, 0, byteCount);
|
||||
}
|
||||
|
||||
out.closeEntry();
|
||||
}
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeZipFileRead(int reps) throws Exception {
|
||||
byte readBuffer[] = new byte[readBufferSize];
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
ZipFile zipFile = new ZipFile(file);
|
||||
for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements(); ) {
|
||||
ZipEntry zipEntry = e.nextElement();
|
||||
InputStream is = zipFile.getInputStream(zipEntry);
|
||||
while (true) {
|
||||
if (is.read(readBuffer, 0, readBuffer.length) < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
zipFile.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,260 @@
|
|||
/*
|
||||
* Copyright (C) 2011 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class AnnotatedElementBenchmark {
|
||||
|
||||
private Class<?> type;
|
||||
private Field field;
|
||||
private Method method;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
type = Type.class;
|
||||
field = Type.class.getField("field");
|
||||
method = Type.class.getMethod("method", String.class);
|
||||
}
|
||||
|
||||
|
||||
// get annotations by member type and method
|
||||
|
||||
public void timeGetTypeAnnotations(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
type.getAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetFieldAnnotations(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
field.getAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetMethodAnnotations(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
method.getAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetParameterAnnotations(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
method.getParameterAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetTypeAnnotation(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
type.getAnnotation(Marker.class);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetFieldAnnotation(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
field.getAnnotation(Marker.class);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetMethodAnnotation(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
method.getAnnotation(Marker.class);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsTypeAnnotationPresent(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
type.isAnnotationPresent(Marker.class);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsFieldAnnotationPresent(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
field.isAnnotationPresent(Marker.class);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsMethodAnnotationPresent(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
method.isAnnotationPresent(Marker.class);
|
||||
}
|
||||
}
|
||||
|
||||
// get annotations by result size
|
||||
|
||||
public void timeGetAllReturnsLargeAnnotation(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
HasLargeAnnotation.class.getAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetAllReturnsSmallAnnotation(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
HasSmallAnnotation.class.getAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetAllReturnsMarkerAnnotation(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
HasMarkerAnnotation.class.getAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetAllReturnsNoAnnotation(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
HasNoAnnotations.class.getAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetAllReturnsThreeAnnotations(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
HasThreeAnnotations.class.getAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// get annotations with inheritance
|
||||
|
||||
public void timeGetAnnotationsOnSubclass(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
ExtendsHasThreeAnnotations.class.getAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetDeclaredAnnotationsOnSubclass(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
ExtendsHasThreeAnnotations.class.getDeclaredAnnotations();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// get annotations with enclosing / inner classes
|
||||
|
||||
public void timeGetDeclaredClasses(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
AnnotatedElementBenchmark.class.getDeclaredClasses();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetDeclaringClass(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
HasSmallAnnotation.class.getDeclaringClass();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetEnclosingClass(int reps) {
|
||||
Object anonymousClass = new Object() {};
|
||||
for (int i = 0; i < reps; i++) {
|
||||
anonymousClass.getClass().getEnclosingClass();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetEnclosingConstructor(int reps) {
|
||||
Object anonymousClass = new Object() {};
|
||||
for (int i = 0; i < reps; i++) {
|
||||
anonymousClass.getClass().getEnclosingConstructor();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetEnclosingMethod(int reps) {
|
||||
Object anonymousClass = new Object() {};
|
||||
for (int i = 0; i < reps; i++) {
|
||||
anonymousClass.getClass().getEnclosingMethod();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetModifiers(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
HasSmallAnnotation.class.getModifiers();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetSimpleName(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
HasSmallAnnotation.class.getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsAnonymousClass(int reps) {
|
||||
Object anonymousClass = new Object() {};
|
||||
for (int i = 0; i < reps; i++) {
|
||||
anonymousClass.getClass().isAnonymousClass();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsLocalClass(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
HasSmallAnnotation.class.isLocalClass();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// the annotated elements
|
||||
|
||||
@Marker
|
||||
public class Type {
|
||||
@Marker public String field;
|
||||
@Marker public void method(@Marker String parameter) {}
|
||||
}
|
||||
|
||||
@Large(a = "on class", b = {"A", "B", "C" },
|
||||
c = @Small(e="E1", f=1695938256, g=7264081114510713000L),
|
||||
d = { @Small(e="E2", f=1695938256, g=7264081114510713000L) })
|
||||
public class HasLargeAnnotation {}
|
||||
|
||||
@Small(e="E1", f=1695938256, g=7264081114510713000L)
|
||||
public class HasSmallAnnotation {}
|
||||
|
||||
@Marker
|
||||
public class HasMarkerAnnotation {}
|
||||
|
||||
public class HasNoAnnotations {}
|
||||
|
||||
@Large(a = "on class", b = {"A", "B", "C" },
|
||||
c = @Small(e="E1", f=1695938256, g=7264081114510713000L),
|
||||
d = { @Small(e="E2", f=1695938256, g=7264081114510713000L) })
|
||||
@Small(e="E1", f=1695938256, g=7264081114510713000L)
|
||||
@Marker
|
||||
public class HasThreeAnnotations {}
|
||||
|
||||
public class ExtendsHasThreeAnnotations extends HasThreeAnnotations {}
|
||||
|
||||
|
||||
// the annotations
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Marker {}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Large {
|
||||
String a() default "";
|
||||
String[] b() default {};
|
||||
Small c() default @Small;
|
||||
Small[] d() default {};
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Small {
|
||||
String e() default "";
|
||||
int f() default 0;
|
||||
long g() default 0L;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.text.Bidi;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class BidiBenchmark {
|
||||
|
||||
private static final AttributedCharacterIterator charIter =
|
||||
DecimalFormat.getInstance().formatToCharacterIterator(new BigDecimal(Math.PI));
|
||||
|
||||
public void time_createBidiFromIter(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Bidi bidi = new Bidi(charIter);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_createBidiFromCharArray(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Bidi bd = new Bidi(new char[]{'s', 's', 's'}, 0, new byte[]{(byte) 1,
|
||||
(byte) 2, (byte) 3}, 0, 3, Bidi.DIRECTION_RIGHT_TO_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_createBidiFromString(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Bidi bidi = new Bidi("Hello", Bidi.DIRECTION_LEFT_TO_RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_reorderVisually(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Bidi.reorderVisually(new byte[]{2, 1, 3, 0, 4}, 0,
|
||||
new String[]{"H", "e", "l", "l", "o"}, 0, 5);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_hebrewBidi(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Bidi bd = new Bidi(new char[]{'\u05D0', '\u05D0', '\u05D0'}, 0,
|
||||
new byte[]{(byte) -1, (byte) -2, (byte) -3}, 0, 3,
|
||||
Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT);
|
||||
bd = new Bidi(new char[]{'\u05D0', '\u05D0', '\u05D0'}, 0,
|
||||
new byte[]{(byte) -1, (byte) -2, (byte) -3}, 0, 3,
|
||||
Bidi.DIRECTION_LEFT_TO_RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_complicatedOverrideBidi(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Bidi bd = new Bidi("a\u05D0a\"a\u05D0\"\u05D0a".toCharArray(), 0,
|
||||
new byte[]{0, 0, 0, -3, -3, 2, 2, 0, 3}, 0, 9,
|
||||
Bidi.DIRECTION_RIGHT_TO_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_requiresBidi(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Bidi.requiresBidi("\u05D0".toCharArray(), 1, 1); // false.
|
||||
Bidi.requiresBidi("\u05D0".toCharArray(), 0, 1); // true.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Random;
|
||||
|
||||
public class BigIntegerBenchmark {
|
||||
public void timeRandomDivision(int reps) throws Exception {
|
||||
Random r = new Random();
|
||||
BigInteger x = new BigInteger(1024, r);
|
||||
BigInteger y = new BigInteger(1024, r);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
x.divide(y);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeRandomGcd(int reps) throws Exception {
|
||||
Random r = new Random();
|
||||
BigInteger x = new BigInteger(1024, r);
|
||||
BigInteger y = new BigInteger(1024, r);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
x.gcd(y);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeRandomMultiplication(int reps) throws Exception {
|
||||
Random r = new Random();
|
||||
BigInteger x = new BigInteger(1024, r);
|
||||
BigInteger y = new BigInteger(1024, r);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
x.multiply(y);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (C) 2011 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Param;
|
||||
import java.util.BitSet;
|
||||
|
||||
public class BitSetBenchmark {
|
||||
@Param({ "1000", "10000" })
|
||||
private int size;
|
||||
|
||||
private BitSet bs;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
bs = new BitSet(size);
|
||||
}
|
||||
|
||||
public void timeIsEmptyTrue(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
if (!bs.isEmpty()) throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsEmptyFalse(int reps) {
|
||||
bs.set(bs.size() - 1);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
if (bs.isEmpty()) throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGet(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
bs.get(i % size);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeClear(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
bs.clear(i % size);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSet(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
bs.set(i % size);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSetOn(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
bs.set(i % size, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSetOff(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
bs.set(i % size, false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
import java.text.BreakIterator;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class BreakIteratorBenchmark {
|
||||
|
||||
public static enum Text {
|
||||
LIPSUM(Locale.US, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi mollis consequat nisl non pharetra. Praesent pretium vehicula odio sed ultrices. Aenean a felis libero. Vivamus sed commodo nibh. Pellentesque turpis lectus, euismod vel ante nec, cursus posuere orci. Suspendisse velit neque, fermentum luctus ultrices in, ultrices vitae arcu. Duis tincidunt cursus lorem. Nam ultricies accumsan quam vitae imperdiet. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Quisque aliquet pretium nisi, eget laoreet enim molestie sit amet. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.\nNam dapibus aliquam lacus ac suscipit. Proin in nibh sit amet purus congue laoreet eget quis nisl. Morbi gravida dignissim justo, a venenatis ante pulvinar at. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ultrices vestibulum dui, vel aliquam lacus aliquam quis. Duis fringilla sapien ac lacus egestas, vel adipiscing elit euismod. Donec non tellus odio. Donec gravida eu massa ac feugiat. Aliquam erat volutpat. Praesent id adipiscing metus, nec laoreet enim. Aliquam vitae posuere turpis. Mauris ac pharetra sem. In at placerat tortor. Vivamus ac vehicula neque. Cras volutpat ullamcorper massa et varius. Praesent sagittis neque vitae nulla euismod pharetra.\nSed placerat sapien non molestie sollicitudin. Nullam sit amet dictum quam. Etiam tincidunt tortor vel pretium vehicula. Praesent fringilla ipsum vel velit luctus dignissim. Nulla massa ligula, mattis in enim et, mattis lacinia odio. Suspendisse tristique urna a orci commodo tempor. Duis lacinia egestas arcu a sollicitudin.\nIn ac feugiat lacus. Nunc fermentum eu est at tristique. Pellentesque quis ligula et orci placerat lacinia. Maecenas quis mauris diam. Etiam mi ipsum, tempus in purus quis, euismod faucibus orci. Nulla facilisi. Praesent sit amet sapien vel elit porta adipiscing. Phasellus sit amet volutpat diam.\nProin bibendum elit non lacus pharetra, quis eleifend tellus placerat. Nulla facilisi. Maecenas ante diam, pellentesque mattis mattis in, porta ut lorem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc interdum tristique metus, in scelerisque odio fermentum eget. Cras nec venenatis lacus. Aenean euismod eget metus quis molestie. Cras tincidunt dolor ut massa ornare, in elementum lacus auctor. Cras sodales nisl lacus, id ultrices ligula varius at. Sed tristique sit amet tellus vel mollis. Sed sed sollicitudin quam. Sed sed adipiscing risus, et dictum orci. Cras tempor pellentesque turpis et tempus."),
|
||||
LONGPARA(Locale.US, "During dinner, Mr. Bennet scarcely spoke at all; but when the servants were withdrawn, he thought it time to have some conversation with his guest, and therefore started a subject in which he expected him to shine, by observing that he seemed very fortunate in his patroness. Lady Catherine de Bourgh's attention to his wishes, and consideration for his comfort, appeared very remarkable. Mr. Bennet could not have chosen better. Mr. Collins was eloquent in her praise. The subject elevated him to more than usual solemnity of manner, and with a most important aspect he protested that \"he had never in his life witnessed such behaviour in a person of rank--such affability and condescension, as he had himself experienced from Lady Catherine. She had been graciously pleased to approve of both of the discourses which he had already had the honour of preaching before her. She had also asked him twice to dine at Rosings, and had sent for him only the Saturday before, to make up her pool of quadrille in the evening. Lady Catherine was reckoned proud by many people he knew, but _he_ had never seen anything but affability in her. She had always spoken to him as she would to any other gentleman; she made not the smallest objection to his joining in the society of the neighbourhood nor to his leaving the parish occasionally for a week or two, to visit his relations. She had even condescended to advise him to marry as soon as he could, provided he chose with discretion; and had once paid him a visit in his humble parsonage, where she had perfectly approved all the alterations he had been making, and had even vouchsafed to suggest some herself--some shelves in the closet up stairs.\""),
|
||||
GERMAN(Locale.GERMANY, "Aber dieser Freiheit setzte endlich der Winter ein Ziel. Draußen auf den Feldern und den hohen Bergen lag der Schnee und Peter wäre in seinem dünnen Leinwandjäckchen bald erfroren. Es war also seine einzige Freude, hinaus vor die Hütte zu treten und den Sperlingen Brotkrümchen zu streuen, was er sich jedesmal an seinem Frühstück absparte. Wenn nun die Vögel so lustig zwitscherten und um ihn herumflogen, da klopfte ihm das Herz vor Lust, und oft gab er ihnen sein ganzes Stück Schwarzbrot, ohne daran zu denken, daß er dafür alsdann selbst hungern müsse."),
|
||||
THAI(Locale.forLanguageTag("th-TH"), "เป็นสำเนียงทางการของภาษาไทย เดิมทีเป็นการผสมผสานกันระหว่างสำเนียงอยุธยาและชาวไทยเชื้อสายจีนรุ่นหลังที่พูดไทยแทนกลุ่มภาษาจีน ลักษณะเด่นคือมีการออกเสียงที่ชัดเจนและแข็งกระด้างซึ่งได้รับอิทธิพลจากภาษาแต้จิ๋ว การออกเสียงพยัญชนะ สระ การผันวรรณยุกต์ที่ในภาษาไทยมาตรฐาน มาจากสำเนียงถิ่นนี้ในขณะที่ภาษาไทยสำเนียงอื่นล้วนเหน่อทั้งสิ้น คำศัพท์ที่ใช้ในสำเนียงกรุงเทพจำนวนมากได้รับมาจากกลุ่มภาษาจีนเช่นคำว่า โป๊, เฮ็ง, อาหมวย, อาซิ่ม ซึ่งมาจากภาษาแต้จิ๋ว และจากภาษาจีนเช่น ถู(涂), ชิ่ว(去 อ่านว่า\"ชู่\") และคำว่า ทาย(猜 อ่านว่า \"ชาย\") เป็นต้น เนื่องจากสำเนียงกรุงเทพได้รับอิทธิพลมาจากภาษาจีนดังนั้นตัวอักษร \"ร\" มักออกเสียงเหมารวมเป็น \"ล\" หรือคำควบกล่ำบางคำถูกละทิ้งไปด้วยเช่น รู้ เป็น ลู้, เรื่อง เป็น เลื่อง หรือ ประเทศ เป็น ปะเทศ เป็นต้นสร้างความลำบากให้แก่ต่างชาติที่ต้องการเรียนภาษาไทย แต่อย่างไรก็ตามผู้ที่พูดสำเนียงถิ่นนี้ก็สามารถออกอักขระภาษาไทยตามมาตรฐานได้อย่างถูกต้องเพียงแต่มักเผลอไม่ค่อยออกเสียง"),
|
||||
THAI2(Locale.forLanguageTag("th-TH"), "this is the word browser in Thai: เบราว์เซอร์"),
|
||||
TABS(Locale.US, "one\t\t\t\t\t\t\t\t\t\t\t\t\t\ttwo\n"),
|
||||
ACCENT(Locale.US, "e\u0301\u00e9\nwhich is:\n\"e\\u0301\\u00e9\""),
|
||||
EMOJI(Locale.US, ">>\ud83d\ude01<<\nwhich is:\n\">>\\ud83d\\ude01<<\""),
|
||||
SPACES(Locale.US, " leading spaces and trailing ones too "),
|
||||
EMPTY(Locale.US, ""),
|
||||
NEWLINE(Locale.US, "\\n:\n"),
|
||||
BIDI(Locale.forLanguageTag("he-IL"), "Sarah שרה is spelled sin ש resh ר heh ה from right to left.");
|
||||
|
||||
final Locale locale;
|
||||
final String text;
|
||||
|
||||
Text(Locale locale, String text) {
|
||||
this.text = text;
|
||||
this.locale = locale;
|
||||
}
|
||||
}
|
||||
|
||||
@Param private Text text;
|
||||
|
||||
public void timeBreakIterator(int nreps) {
|
||||
for (int i = 0; i < nreps; ++i) {
|
||||
BreakIterator it = BreakIterator.getLineInstance(text.locale);
|
||||
it.setText(text.text);
|
||||
|
||||
while (it.next() != BreakIterator.DONE) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIcuBreakIterator(int nreps) {
|
||||
for (int i = 0; i < nreps; ++i) {
|
||||
android.icu.text.BreakIterator it =
|
||||
android.icu.text.BreakIterator.getLineInstance(text.locale);
|
||||
it.setText(text.text);
|
||||
|
||||
while (it.next() != android.icu.text.BreakIterator.DONE) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,415 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.DoubleBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.LongBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
public class ByteBufferBenchmark {
|
||||
public enum MyByteOrder {
|
||||
BIG(ByteOrder.BIG_ENDIAN), LITTLE(ByteOrder.LITTLE_ENDIAN);
|
||||
final ByteOrder byteOrder;
|
||||
MyByteOrder(ByteOrder byteOrder) {
|
||||
this.byteOrder = byteOrder;
|
||||
}
|
||||
}
|
||||
|
||||
@Param private MyByteOrder byteOrder;
|
||||
|
||||
@Param({"true", "false"}) private boolean aligned;
|
||||
|
||||
enum MyBufferType {
|
||||
DIRECT, HEAP, MAPPED;
|
||||
}
|
||||
@Param private MyBufferType bufferType;
|
||||
|
||||
public static ByteBuffer newBuffer(MyByteOrder byteOrder, boolean aligned, MyBufferType bufferType) throws IOException {
|
||||
int size = aligned ? 8192 : 8192 + 8 + 1;
|
||||
ByteBuffer result = null;
|
||||
switch (bufferType) {
|
||||
case DIRECT:
|
||||
result = ByteBuffer.allocateDirect(size);
|
||||
break;
|
||||
case HEAP:
|
||||
result = ByteBuffer.allocate(size);
|
||||
break;
|
||||
case MAPPED:
|
||||
File tmpFile = new File("/sdcard/bm.tmp");
|
||||
if (new File("/tmp").isDirectory()) {
|
||||
// We're running on the desktop.
|
||||
tmpFile = File.createTempFile("MappedByteBufferTest", ".tmp");
|
||||
}
|
||||
tmpFile.createNewFile();
|
||||
tmpFile.deleteOnExit();
|
||||
RandomAccessFile raf = new RandomAccessFile(tmpFile, "rw");
|
||||
raf.setLength(8192*8);
|
||||
FileChannel fc = raf.getChannel();
|
||||
result = fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size());
|
||||
break;
|
||||
}
|
||||
result.order(byteOrder.byteOrder);
|
||||
result.position(aligned ? 0 : 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// peeking
|
||||
//
|
||||
|
||||
public void timeByteBuffer_getByte(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_getByteArray(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
byte[] dst = new byte[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
src.get(dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_getByte_indexed(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.get(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_getChar(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.getChar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCharBuffer_getCharArray(int reps) throws Exception {
|
||||
CharBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType).asCharBuffer();
|
||||
char[] dst = new char[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.position(0);
|
||||
src.get(dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_getChar_indexed(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.getChar(i * 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_getDouble(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.getDouble();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeDoubleBuffer_getDoubleArray(int reps) throws Exception {
|
||||
DoubleBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType).asDoubleBuffer();
|
||||
double[] dst = new double[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.position(0);
|
||||
src.get(dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_getFloat(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.getFloat();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeFloatBuffer_getFloatArray(int reps) throws Exception {
|
||||
FloatBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType).asFloatBuffer();
|
||||
float[] dst = new float[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.position(0);
|
||||
src.get(dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_getInt(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.getInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIntBuffer_getIntArray(int reps) throws Exception {
|
||||
IntBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType).asIntBuffer();
|
||||
int[] dst = new int[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.position(0);
|
||||
src.get(dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_getLong(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.getLong();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeLongBuffer_getLongArray(int reps) throws Exception {
|
||||
LongBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType).asLongBuffer();
|
||||
long[] dst = new long[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.position(0);
|
||||
src.get(dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_getShort(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.getShort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeShortBuffer_getShortArray(int reps) throws Exception {
|
||||
ShortBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType).asShortBuffer();
|
||||
short[] dst = new short[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.position(0);
|
||||
src.get(dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// poking
|
||||
//
|
||||
|
||||
public void timeByteBuffer_putByte(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(0);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.put((byte) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_putByteArray(int reps) throws Exception {
|
||||
ByteBuffer dst = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
byte[] src = new byte[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
dst.position(aligned ? 0 : 1);
|
||||
dst.put(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_putChar(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.putChar(' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCharBuffer_putCharArray(int reps) throws Exception {
|
||||
CharBuffer dst = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType).asCharBuffer();
|
||||
char[] src = new char[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
dst.position(0);
|
||||
dst.put(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_putDouble(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.putDouble(0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeDoubleBuffer_putDoubleArray(int reps) throws Exception {
|
||||
DoubleBuffer dst = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType).asDoubleBuffer();
|
||||
double[] src = new double[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
dst.position(0);
|
||||
dst.put(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_putFloat(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.putFloat(0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeFloatBuffer_putFloatArray(int reps) throws Exception {
|
||||
FloatBuffer dst = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType).asFloatBuffer();
|
||||
float[] src = new float[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
dst.position(0);
|
||||
dst.put(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_putInt(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.putInt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIntBuffer_putIntArray(int reps) throws Exception {
|
||||
IntBuffer dst = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType).asIntBuffer();
|
||||
int[] src = new int[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
dst.position(0);
|
||||
dst.put(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_putLong(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.putLong(0L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeLongBuffer_putLongArray(int reps) throws Exception {
|
||||
LongBuffer dst = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType).asLongBuffer();
|
||||
long[] src = new long[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
dst.position(0);
|
||||
dst.put(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBuffer_putShort(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
src.putShort((short) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeShortBuffer_putShortArray(int reps) throws Exception {
|
||||
ShortBuffer dst = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType).asShortBuffer();
|
||||
short[] src = new short[1024];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
dst.position(0);
|
||||
dst.put(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void time_new_byteArray(int reps) throws Exception {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
byte[] bs = new byte[8192];
|
||||
}
|
||||
}
|
||||
|
||||
public void time_ByteBuffer_allocate(int reps) throws Exception {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
ByteBuffer bs = ByteBuffer.allocate(8192);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (C) 2016 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.DoubleBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.LongBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
public class ByteBufferBulkBenchmark {
|
||||
@Param({"true", "false"}) private boolean aligned;
|
||||
|
||||
|
||||
enum MyBufferType {
|
||||
DIRECT, HEAP, MAPPED
|
||||
}
|
||||
@Param private MyBufferType srcBufferType;
|
||||
@Param private MyBufferType dataBufferType;
|
||||
|
||||
@Param({"4096", "1232896"}) private int bufferSize;
|
||||
|
||||
public static ByteBuffer newBuffer(boolean aligned, MyBufferType bufferType, int bsize) throws IOException {
|
||||
int size = aligned ? bsize : bsize + 8 + 1;
|
||||
ByteBuffer result = null;
|
||||
switch (bufferType) {
|
||||
case DIRECT:
|
||||
result = ByteBuffer.allocateDirect(size);
|
||||
break;
|
||||
case HEAP:
|
||||
result = ByteBuffer.allocate(size);
|
||||
break;
|
||||
case MAPPED:
|
||||
File tmpFile = File.createTempFile("MappedByteBufferTest", ".tmp");
|
||||
tmpFile.createNewFile();
|
||||
tmpFile.deleteOnExit();
|
||||
RandomAccessFile raf = new RandomAccessFile(tmpFile, "rw");
|
||||
raf.setLength(size);
|
||||
FileChannel fc = raf.getChannel();
|
||||
result = fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size());
|
||||
break;
|
||||
}
|
||||
result.position(aligned ? 0 : 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void timeByteBuffer_putByteBuffer(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBulkBenchmark.newBuffer(aligned, srcBufferType, bufferSize);
|
||||
ByteBuffer data = ByteBufferBulkBenchmark.newBuffer(aligned, dataBufferType, bufferSize);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
data.position(aligned ? 0 : 1 );
|
||||
src.put(data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class ByteBufferScalarVersusVectorBenchmark {
|
||||
@Param private ByteBufferBenchmark.MyByteOrder byteOrder;
|
||||
@Param({"true", "false"}) private boolean aligned;
|
||||
@Param private ByteBufferBenchmark.MyBufferType bufferType;
|
||||
|
||||
public void timeManualByteBufferCopy(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
ByteBuffer dst = ByteBufferBenchmark.newBuffer(byteOrder, aligned, bufferType);
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(0);
|
||||
dst.position(0);
|
||||
for (int i = 0; i < 8192; ++i) {
|
||||
dst.put(src.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeByteBufferBulkGet(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBuffer.allocate(aligned ? 8192 : 8192 + 1);
|
||||
byte[] dst = new byte[8192];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
src.get(dst, 0, dst.length);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeDirectByteBufferBulkGet(int reps) throws Exception {
|
||||
ByteBuffer src = ByteBuffer.allocateDirect(aligned ? 8192 : 8192 + 1);
|
||||
byte[] dst = new byte[8192];
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
src.position(aligned ? 0 : 1);
|
||||
src.get(dst, 0, dst.length);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,299 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Param;
|
||||
|
||||
/**
|
||||
* Tests various Character methods, intended for testing multiple
|
||||
* implementations against each other.
|
||||
*/
|
||||
public class CharacterBenchmark {
|
||||
|
||||
@Param private CharacterSet characterSet;
|
||||
|
||||
@Param private Overload overload;
|
||||
|
||||
private char[] chars;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
this.chars = characterSet.chars;
|
||||
}
|
||||
|
||||
public enum Overload { CHAR, INT }
|
||||
|
||||
public double nanosToUnits(double nanos) {
|
||||
return nanos / 65536;
|
||||
}
|
||||
|
||||
public enum CharacterSet {
|
||||
ASCII(128),
|
||||
UNICODE(65536);
|
||||
final char[] chars;
|
||||
CharacterSet(int size) {
|
||||
this.chars = new char[65536];
|
||||
for (int i = 0; i < 65536; ++i) {
|
||||
chars[i] = (char) (i % size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A fake benchmark to give us a baseline.
|
||||
public boolean timeIsSpace(int reps) {
|
||||
boolean fake = false;
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
fake ^= ((char) ch == ' ');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
fake ^= (ch == ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
return fake;
|
||||
}
|
||||
|
||||
public void timeDigit(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.digit(chars[ch], 10);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.digit((int) chars[ch], 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetNumericValue(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.getNumericValue(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.getNumericValue((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsDigit(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isDigit(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isDigit((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsIdentifierIgnorable(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isIdentifierIgnorable(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isIdentifierIgnorable((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsJavaIdentifierPart(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isJavaIdentifierPart(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isJavaIdentifierPart((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsJavaIdentifierStart(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isJavaIdentifierStart(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isJavaIdentifierStart((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsLetter(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isLetter(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isLetter((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsLetterOrDigit(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isLetterOrDigit(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isLetterOrDigit((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsLowerCase(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isLowerCase(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isLowerCase((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsSpaceChar(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isSpaceChar(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isSpaceChar((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsUpperCase(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isUpperCase(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isUpperCase((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIsWhitespace(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isWhitespace(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.isWhitespace((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeToLowerCase(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.toLowerCase(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.toLowerCase((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeToUpperCase(int reps) {
|
||||
if (overload == Overload.CHAR) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.toUpperCase(chars[ch]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int ch = 0; ch < 65536; ++ch) {
|
||||
Character.toUpperCase((int) chars[ch]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
|
||||
public class CharsetBenchmark {
|
||||
@Param({ "1", "10", "100", "1000", "10000" })
|
||||
private int length;
|
||||
|
||||
// canonical => canonical charset name
|
||||
// built-in => guaranteed-present charset
|
||||
// special-case => libcore treats this charset specially for performance
|
||||
@Param({
|
||||
"UTF-16", // canonical, built-in, non-special-case
|
||||
"UTF-8", // canonical, built-in, special-case
|
||||
"UTF8", // non-canonical, built-in, special-case
|
||||
"ISO-8859-1", // canonical, built-in, special-case
|
||||
"8859_1", // non-canonical, built-in, special-case
|
||||
"ISO-8859-2", // canonical, non-built-in, non-special-case
|
||||
"8859_2", // non-canonical, non-built-in, non-special-case
|
||||
"US-ASCII", // canonical, built-in, special-case
|
||||
"ASCII" // non-canonical, built-in, special-case
|
||||
})
|
||||
private String name;
|
||||
|
||||
public void time_new_String_BString(int reps) throws Exception {
|
||||
byte[] bytes = makeBytes(makeString(length));
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
new String(bytes, name);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_new_String_BII(int reps) throws Exception {
|
||||
byte[] bytes = makeBytes(makeString(length));
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
new String(bytes, 0, bytes.length);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_new_String_BIIString(int reps) throws Exception {
|
||||
byte[] bytes = makeBytes(makeString(length));
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
new String(bytes, 0, bytes.length, name);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_String_getBytes(int reps) throws Exception {
|
||||
String string = makeString(length);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
string.getBytes(name);
|
||||
}
|
||||
}
|
||||
|
||||
private static String makeString(int length) {
|
||||
StringBuilder result = new StringBuilder(length);
|
||||
for (int i = 0; i < length; ++i) {
|
||||
result.append('A' + (i % 26));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static byte[] makeBytes(String s) {
|
||||
try {
|
||||
return s.getBytes("US-ASCII");
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class CharsetForNameBenchmark {
|
||||
// canonical => canonical charset name
|
||||
// built-in => guaranteed-present charset
|
||||
// special-case => libcore treats this charset specially for performance
|
||||
@Param({
|
||||
"UTF-16", // canonical, built-in, non-special-case
|
||||
"UTF-8", // canonical, built-in, special-case
|
||||
"UTF8", // non-canonical, built-in, special-case
|
||||
"ISO-8859-1", // canonical, built-in, special-case
|
||||
"8859_1", // non-canonical, built-in, special-case
|
||||
"ISO-8859-2", // canonical, non-built-in, non-special-case
|
||||
"8859_2", // non-canonical, non-built-in, non-special-case
|
||||
"US-ASCII", // canonical, built-in, special-case
|
||||
"ASCII" // non-canonical, built-in, special-case
|
||||
})
|
||||
private String charsetName;
|
||||
|
||||
public void timeCharsetForName(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
Charset.forName(charsetName);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package benchmarks.regression;
|
||||
|
||||
import android.icu.lang.UCharacter;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Decode the same size of ASCII, BMP, Supplementary character using fast-path UTF-8 decoder.
|
||||
* The fast-path code is in {@link StringFactory#newStringFromBytes(byte[], int, int, Charset)}
|
||||
*/
|
||||
public class CharsetUtf8Benchmark {
|
||||
|
||||
private static final int NO_OF_BYTES = 0x400000; // 4MB
|
||||
private static final byte[] ASCII = makeUnicodeRange(0, 0x7f, NO_OF_BYTES / 0x80);
|
||||
private static final byte[] BMP2 = makeUnicodeRange(0x0080, 0x07ff, NO_OF_BYTES / 2 / 0x780);
|
||||
private static final byte[] BMP3 = makeUnicodeRange(0x0800, 0xffff,
|
||||
NO_OF_BYTES / 3 / 0xf000 /* 0x10000 - 0x0800 - no of surrogate code points */);
|
||||
private static final byte[] SUPPLEMENTARY = makeUnicodeRange(0x10000, 0x10ffff,
|
||||
NO_OF_BYTES / 4 / 0x100000);
|
||||
|
||||
private static byte[] makeUnicodeRange(int startingCodePoint, int endingCodePoint,
|
||||
int repeated) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int codePoint = startingCodePoint; codePoint <= endingCodePoint; codePoint++) {
|
||||
if (codePoint < Character.MIN_SURROGATE || codePoint > Character.MAX_SURROGATE) {
|
||||
builder.append(UCharacter.toString(codePoint));
|
||||
}
|
||||
}
|
||||
|
||||
String str = builder.toString();
|
||||
builder = new StringBuilder();
|
||||
for (int i = 0; i < repeated; i++) {
|
||||
builder.append(str);
|
||||
}
|
||||
return builder.toString().getBytes();
|
||||
}
|
||||
|
||||
public void time_ascii() {
|
||||
new String(ASCII, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public void time_bmp2() {
|
||||
new String(BMP2, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public void time_bmp3() {
|
||||
new String(BMP3, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public void time_supplementary() {
|
||||
new String(SUPPLEMENTARY, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.util.zip.Adler32;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
public class ChecksumBenchmark {
|
||||
public void timeAdler_block(int reps) throws Exception {
|
||||
byte[] bytes = new byte[10000];
|
||||
Adler32 adler = new Adler32();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
adler.update(bytes);
|
||||
}
|
||||
}
|
||||
public void timeAdler_byte(int reps) throws Exception {
|
||||
Adler32 adler = new Adler32();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
adler.update(1);
|
||||
}
|
||||
}
|
||||
public void timeCrc_block(int reps) throws Exception {
|
||||
byte[] bytes = new byte[10000];
|
||||
CRC32 crc = new CRC32();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
crc.update(bytes);
|
||||
}
|
||||
}
|
||||
public void timeCrc_byte(int reps) throws Exception {
|
||||
CRC32 crc = new CRC32();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
crc.update(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Param;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
|
||||
/**
|
||||
* Cipher benchmarks. Only runs on AES currently because of the combinatorial
|
||||
* explosion of the test as it stands.
|
||||
*/
|
||||
public class CipherBenchmark {
|
||||
|
||||
private static final int DATA_SIZE = 8192;
|
||||
private static final byte[] DATA = new byte[DATA_SIZE];
|
||||
|
||||
private static final int IV_SIZE = 16;
|
||||
|
||||
private static final byte[] IV = new byte[IV_SIZE];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < DATA_SIZE; i++) {
|
||||
DATA[i] = (byte) i;
|
||||
}
|
||||
for (int i = 0; i < IV_SIZE; i++) {
|
||||
IV[i] = (byte) i;
|
||||
}
|
||||
}
|
||||
|
||||
@Param private Algorithm algorithm;
|
||||
|
||||
public enum Algorithm {
|
||||
AES,
|
||||
};
|
||||
|
||||
@Param private Mode mode;
|
||||
|
||||
public enum Mode {
|
||||
CBC,
|
||||
CFB,
|
||||
CTR,
|
||||
ECB,
|
||||
OFB,
|
||||
};
|
||||
|
||||
@Param private Padding padding;
|
||||
|
||||
public enum Padding {
|
||||
NOPADDING,
|
||||
PKCS1PADDING,
|
||||
};
|
||||
|
||||
@Param({"128", "192", "256"}) private int keySize;
|
||||
|
||||
@Param({"16", "32", "64", "128", "1024", "8192"}) private int inputSize;
|
||||
|
||||
@Param private Implementation implementation;
|
||||
|
||||
public enum Implementation { OpenSSL, BouncyCastle };
|
||||
|
||||
private String providerName;
|
||||
|
||||
// Key generation isn't part of the benchmark so cache the results
|
||||
private static Map<Integer, SecretKey> KEY_SIZES = new HashMap<Integer, SecretKey>();
|
||||
|
||||
private String cipherAlgorithm;
|
||||
private SecretKey key;
|
||||
|
||||
private byte[] output = new byte[DATA.length];
|
||||
|
||||
private Cipher cipherEncrypt;
|
||||
|
||||
private Cipher cipherDecrypt;
|
||||
|
||||
private AlgorithmParameterSpec spec;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
cipherAlgorithm = algorithm.toString() + "/" + mode.toString() + "/"
|
||||
+ padding.toString();
|
||||
|
||||
String keyAlgorithm = algorithm.toString();
|
||||
key = KEY_SIZES.get(keySize);
|
||||
if (key == null) {
|
||||
KeyGenerator generator = KeyGenerator.getInstance(keyAlgorithm);
|
||||
generator.init(keySize);
|
||||
key = generator.generateKey();
|
||||
KEY_SIZES.put(keySize, key);
|
||||
}
|
||||
|
||||
switch (implementation) {
|
||||
case OpenSSL:
|
||||
providerName = "AndroidOpenSSL";
|
||||
break;
|
||||
case BouncyCastle:
|
||||
providerName = "BC";
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(implementation.toString());
|
||||
}
|
||||
|
||||
if (mode != Mode.ECB) {
|
||||
spec = new IvParameterSpec(IV);
|
||||
}
|
||||
|
||||
cipherEncrypt = Cipher.getInstance(cipherAlgorithm, providerName);
|
||||
cipherEncrypt.init(Cipher.ENCRYPT_MODE, key, spec);
|
||||
|
||||
cipherDecrypt = Cipher.getInstance(cipherAlgorithm, providerName);
|
||||
cipherDecrypt.init(Cipher.DECRYPT_MODE, key, spec);
|
||||
}
|
||||
|
||||
public void timeEncrypt(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
cipherEncrypt.doFinal(DATA, 0, inputSize, output);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeDecrypt(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
cipherDecrypt.doFinal(DATA, 0, inputSize, output);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.CipherInputStream;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
|
||||
/**
|
||||
* CipherInputStream benchmark.
|
||||
*/
|
||||
public class CipherInputStreamBenchmark {
|
||||
|
||||
private static final int DATA_SIZE = 1024 * 1024;
|
||||
private static final byte[] DATA = new byte[DATA_SIZE];
|
||||
|
||||
private static final int IV_SIZE = 16;
|
||||
private static final byte[] IV = new byte[IV_SIZE];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < DATA_SIZE; i++) {
|
||||
DATA[i] = (byte) i;
|
||||
}
|
||||
for (int i = 0; i < IV_SIZE; i++) {
|
||||
IV[i] = (byte) i;
|
||||
}
|
||||
}
|
||||
|
||||
private SecretKey key;
|
||||
|
||||
private byte[] output = new byte[8192];
|
||||
|
||||
private Cipher cipherEncrypt;
|
||||
|
||||
private AlgorithmParameterSpec spec;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
KeyGenerator generator = KeyGenerator.getInstance("AES");
|
||||
generator.init(128);
|
||||
key = generator.generateKey();
|
||||
|
||||
spec = new IvParameterSpec(IV);
|
||||
|
||||
cipherEncrypt = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipherEncrypt.init(Cipher.ENCRYPT_MODE, key, spec);
|
||||
}
|
||||
|
||||
public void timeEncrypt(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
cipherEncrypt.init(Cipher.ENCRYPT_MODE, key, spec);
|
||||
InputStream is = new CipherInputStream(new ByteArrayInputStream(DATA), cipherEncrypt);
|
||||
while (is.read(output) != -1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.text.RuleBasedCollator;
|
||||
import java.util.Locale;
|
||||
|
||||
public class CollatorBenchmark {
|
||||
|
||||
private static final RuleBasedCollator collator = (RuleBasedCollator)
|
||||
Collator.getInstance(Locale.US);
|
||||
|
||||
public void timeCollatorPrimary(int reps) {
|
||||
collator.setStrength(Collator.PRIMARY);
|
||||
for (int i = 0; i < reps; i++) {
|
||||
collator.compare("abcde", "abcdf");
|
||||
collator.compare("abcde", "abcde");
|
||||
collator.compare("abcdf", "abcde");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCollatorSecondary(int reps) {
|
||||
collator.setStrength(Collator.SECONDARY);
|
||||
for (int i = 0; i < reps; i++) {
|
||||
collator.compare("abcdÂ", "abcdÄ");
|
||||
collator.compare("abcdÂ", "abcdÂ");
|
||||
collator.compare("abcdÄ", "abcdÂ");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCollatorTertiary(int reps) {
|
||||
collator.setStrength(Collator.TERTIARY);
|
||||
for (int i = 0; i < reps; i++) {
|
||||
collator.compare("abcdE", "abcde");
|
||||
collator.compare("abcde", "abcde");
|
||||
collator.compare("abcde", "abcdE");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeCollatorIdentical(int reps) {
|
||||
collator.setStrength(Collator.IDENTICAL);
|
||||
for (int i = 0; i < reps; i++) {
|
||||
collator.compare("abcdȪ", "abcdȫ");
|
||||
collator.compare("abcdȪ", "abcdȪ");
|
||||
collator.compare("abcdȫ", "abcdȪ");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (C) 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
|
||||
public class CollectionsBenchmark {
|
||||
@Param({"4", "16", "64", "256", "1024"})
|
||||
private int arrayListLength;
|
||||
|
||||
public static Comparator<Integer> REVERSE = new Comparator<Integer>() {
|
||||
@Override
|
||||
public int compare(Integer lhs, Integer rhs) {
|
||||
int lhsAsInt = lhs.intValue();
|
||||
int rhsAsInt = rhs.intValue();
|
||||
return rhsAsInt < lhsAsInt ? -1 : (lhsAsInt == rhsAsInt ? 0 : 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public void timeSort_arrayList(int nreps) throws Exception {
|
||||
List<Integer> input = buildList(arrayListLength, ArrayList.class);
|
||||
for (int i = 0; i < nreps; ++i) {
|
||||
Collections.sort(input);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSortWithComparator_arrayList(int nreps) throws Exception {
|
||||
List<Integer> input = buildList(arrayListLength, ArrayList.class);
|
||||
for (int i = 0; i < nreps; ++i) {
|
||||
Collections.sort(input, REVERSE);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSort_vector(int nreps) throws Exception {
|
||||
List<Integer> input = buildList(arrayListLength, Vector.class);
|
||||
for (int i = 0; i < nreps; ++i) {
|
||||
Collections.sort(input);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSortWithComparator_vector(int nreps) throws Exception {
|
||||
List<Integer> input = buildList(arrayListLength, Vector.class);
|
||||
for (int i = 0; i < nreps; ++i) {
|
||||
Collections.sort(input, REVERSE);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T extends List<Integer>> List<Integer> buildList(
|
||||
int arrayListLength, Class<T> listClass) throws Exception {
|
||||
Random random = new Random();
|
||||
random.setSeed(0);
|
||||
List<Integer> list = listClass.newInstance();
|
||||
for (int i = 0; i < arrayListLength; ++i) {
|
||||
list.add(random.nextInt());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (C) 2016 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class DateFormatBenchmark {
|
||||
|
||||
private Locale locale1;
|
||||
private Locale locale2;
|
||||
private Locale locale3;
|
||||
private Locale locale4;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
locale1 = Locale.TAIWAN;
|
||||
locale2 = Locale.GERMANY;
|
||||
locale3 = Locale.FRANCE;
|
||||
locale4 = Locale.ITALY;
|
||||
}
|
||||
|
||||
public void timeGetDateTimeInstance(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
DateFormat.getDateTimeInstance();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeGetDateTimeInstance_multiple(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale1);
|
||||
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale2);
|
||||
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale3);
|
||||
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale4);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
package benchmarks.regression;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
public class DecimalFormatBenchmark {
|
||||
|
||||
private static final String EXP_PATTERN = "##E0";
|
||||
|
||||
private static final DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance();
|
||||
// Keep patternInstance for timing with patterns, to not dirty the plain instance.
|
||||
private static final DecimalFormat patternInstance = (DecimalFormat)
|
||||
DecimalFormat.getInstance();
|
||||
private static final DecimalFormat dfCurrencyUS = (DecimalFormat)
|
||||
NumberFormat.getCurrencyInstance(Locale.US);
|
||||
private static final DecimalFormat dfCurrencyFR = (DecimalFormat)
|
||||
NumberFormat.getInstance(Locale.FRANCE);
|
||||
|
||||
private static final BigDecimal BD10E3 = new BigDecimal("10E3");
|
||||
private static final BigDecimal BD10E9 = new BigDecimal("10E9");
|
||||
private static final BigDecimal BD10E100 = new BigDecimal("10E100");
|
||||
private static final BigDecimal BD10E1000 = new BigDecimal("10E1000");
|
||||
|
||||
private static final int WHOLE_NUMBER = 10;
|
||||
private static final double TWO_DP_NUMBER = 3.14;
|
||||
|
||||
public static void formatWithGrouping(Object obj, int reps) {
|
||||
df.setGroupingSize(3);
|
||||
df.setGroupingUsed(true);
|
||||
for (int i = 0; i < reps; i++) {
|
||||
df.format(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static void format(String pattern, Object obj, int reps) {
|
||||
patternInstance.applyPattern(pattern);
|
||||
for (int i = 0; i < reps; i++) {
|
||||
patternInstance.format(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static void format(Object obj, int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
df.format(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static void formatToCharacterIterator(Object obj, int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
df.formatToCharacterIterator(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void formatCurrencyUS(Object obj, int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
dfCurrencyUS.format(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static void formatCurrencyFR(Object obj, int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
dfCurrencyFR.format(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_formatGrouping_BigDecimal10e3(int reps) {
|
||||
formatWithGrouping(BD10E3, reps);
|
||||
}
|
||||
|
||||
public void time_formatGrouping_BigDecimal10e9(int reps) {
|
||||
formatWithGrouping(BD10E9, reps);
|
||||
}
|
||||
|
||||
public void time_formatGrouping_BigDecimal10e100(int reps) {
|
||||
formatWithGrouping(BD10E100, reps);
|
||||
}
|
||||
|
||||
public void time_formatGrouping_BigDecimal10e1000(int reps) {
|
||||
formatWithGrouping(BD10E1000, reps);
|
||||
}
|
||||
|
||||
public void time_formatBigDecimal10e3(int reps) {
|
||||
format(BD10E3, reps);
|
||||
}
|
||||
|
||||
public void time_formatBigDecimal10e9(int reps) {
|
||||
format(BD10E9, reps);
|
||||
}
|
||||
|
||||
public void time_formatBigDecimal10e100(int reps) {
|
||||
format(BD10E100, reps);
|
||||
}
|
||||
|
||||
public void time_formatBigDecimal10e1000(int reps) {
|
||||
format(BD10E1000, reps);
|
||||
}
|
||||
|
||||
public void time_formatPi(int reps) {
|
||||
format(Math.PI, reps);
|
||||
}
|
||||
|
||||
public void time_formatE(int reps) {
|
||||
format(Math.E, reps);
|
||||
}
|
||||
|
||||
public void time_formatUSD(int reps) {
|
||||
formatCurrencyUS(WHOLE_NUMBER, reps);
|
||||
}
|
||||
|
||||
public void time_formatUsdWithCents(int reps) {
|
||||
formatCurrencyUS(TWO_DP_NUMBER, reps);
|
||||
}
|
||||
|
||||
public void time_formatEur(int reps) {
|
||||
formatCurrencyFR(WHOLE_NUMBER, reps);
|
||||
}
|
||||
|
||||
public void time_formatEurWithCents(int reps) {
|
||||
formatCurrencyFR(TWO_DP_NUMBER, reps);
|
||||
}
|
||||
|
||||
public void time_formatAsExponent10e3(int reps) {
|
||||
format(EXP_PATTERN, BD10E3, reps);
|
||||
}
|
||||
|
||||
public void time_formatAsExponent10e9(int reps) {
|
||||
format(EXP_PATTERN, BD10E9, reps);
|
||||
}
|
||||
|
||||
public void time_formatAsExponent10e100(int reps) {
|
||||
format(EXP_PATTERN, BD10E100, reps);
|
||||
}
|
||||
|
||||
public void time_formatAsExponent10e1000(int reps) {
|
||||
format(EXP_PATTERN, BD10E1000, reps);
|
||||
}
|
||||
|
||||
public void time_formatToCharacterIterator10e3(int reps) {
|
||||
formatToCharacterIterator(BD10E3, reps);
|
||||
}
|
||||
|
||||
public void time_formatToCharacterIterator10e9(int reps) {
|
||||
formatToCharacterIterator(BD10E9, reps);
|
||||
}
|
||||
|
||||
public void time_formatToCharacterIterator10e100(int reps) {
|
||||
formatToCharacterIterator(BD10E100, reps);
|
||||
}
|
||||
|
||||
public void time_formatToCharacterIterator10e1000(int reps) {
|
||||
formatToCharacterIterator(BD10E1000, reps);
|
||||
}
|
||||
|
||||
public void time_instantiation(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
new DecimalFormat();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
public class DecimalFormatSymbolsBenchmark {
|
||||
|
||||
private static Locale locale = Locale.getDefault(Locale.Category.FORMAT);
|
||||
|
||||
public void time_instantiation(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
new DecimalFormatSymbols(locale);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class DefaultCharsetBenchmark {
|
||||
public void time_defaultCharset(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
Charset.defaultCharset();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
public class DnsBenchmark {
|
||||
public void timeDns(int reps) throws Exception {
|
||||
String[] hosts = new String[] {
|
||||
"www.amazon.com",
|
||||
"z-ecx.images-amazon.com",
|
||||
"g-ecx.images-amazon.com",
|
||||
"ecx.images-amazon.com",
|
||||
"ad.doubleclick.com",
|
||||
"bpx.a9.com",
|
||||
"d3dtik4dz1nej0.cloudfront.net",
|
||||
"uac.advertising.com",
|
||||
"servedby.advertising.com",
|
||||
"view.atdmt.com",
|
||||
"rmd.atdmt.com",
|
||||
"spe.atdmt.com",
|
||||
"www.google.com",
|
||||
"www.cnn.com",
|
||||
"bad.host.mtv.corp.google.com",
|
||||
};
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
try {
|
||||
InetAddress.getByName(hosts[i % hosts.length]);
|
||||
} catch (UnknownHostException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
public class DoPrivilegedBenchmark {
|
||||
public void timeDirect(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
String lineSeparator = System.getProperty("line.separator");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeFastAndSlow(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
String lineSeparator;
|
||||
if (System.getSecurityManager() == null) {
|
||||
lineSeparator = System.getProperty("line.separator");
|
||||
} else {
|
||||
lineSeparator = AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
return System.getProperty("line.separator");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeNewAction(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
String lineSeparator = AccessController.doPrivileged(new PrivilegedAction<String>() {
|
||||
public String run() {
|
||||
return System.getProperty("line.separator");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void timeReusedAction(int reps) throws Exception {
|
||||
final PrivilegedAction<String> action = new ReusableAction("line.separator");
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
String lineSeparator = AccessController.doPrivileged(action);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ReusableAction implements PrivilegedAction<String> {
|
||||
private final String propertyName;
|
||||
|
||||
public ReusableAction(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public String run() {
|
||||
return System.getProperty(propertyName);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
public class DoubleBenchmark {
|
||||
private double d = 1.2;
|
||||
private long l = 4608083138725491507L;
|
||||
|
||||
public void timeDoubleToLongBits(int reps) {
|
||||
long result = 123;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Double.doubleToLongBits(d);
|
||||
}
|
||||
if (result != l) {
|
||||
throw new RuntimeException(Long.toString(result));
|
||||
}
|
||||
}
|
||||
|
||||
public void timeDoubleToRawLongBits(int reps) {
|
||||
long result = 123;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Double.doubleToRawLongBits(d);
|
||||
}
|
||||
if (result != l) {
|
||||
throw new RuntimeException(Long.toString(result));
|
||||
}
|
||||
}
|
||||
|
||||
public void timeLongBitsToDouble(int reps) {
|
||||
double result = 123.0;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Double.longBitsToDouble(l);
|
||||
}
|
||||
if (result != d) {
|
||||
throw new RuntimeException(Double.toString(result) + " " + Double.doubleToRawLongBits(result));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (C) 2011 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Param;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
public final class EqualsHashCodeBenchmark {
|
||||
private enum Type {
|
||||
URI() {
|
||||
@Override Object newInstance(String text) throws Exception {
|
||||
return new URI(text);
|
||||
}
|
||||
},
|
||||
URL() {
|
||||
@Override Object newInstance(String text) throws Exception {
|
||||
return new URL(text);
|
||||
}
|
||||
};
|
||||
abstract Object newInstance(String text) throws Exception;
|
||||
}
|
||||
|
||||
private static final String QUERY = "%E0%AE%A8%E0%AE%BE%E0%AE%AE%E0%AF%8D+%E0%AE%AE%E0%AF%81%E0%AE%95%E0%AF%8D%E0%AE%95%E0%AE%BF%E0%AE%AF%E0%AE%AE%E0%AE%BE%E0%AE%A9%2C+%E0%AE%9A%E0%AF%81%E0%AE%B5%E0%AE%BE%E0%AE%B0%E0%AE%B8%E0%AF%8D%E0%AE%AF%E0%AE%AE%E0%AE%BE%E0%AE%A9+%E0%AE%87%E0%AE%B0%E0%AF%81%E0%AE%AA%E0%AF%8D%E0%AE%AA%E0%AF%87%E0%AE%BE%E0%AE%AE%E0%AF%8D%2C+%E0%AE%86%E0%AE%A9%E0%AE%BE%E0%AE%B2%E0%AF%8D+%E0%AE%9A%E0%AE%BF%E0%AE%B2+%E0%AE%A8%E0%AF%87%E0%AE%B0%E0%AE%99%E0%AF%8D%E0%AE%95%E0%AE%B3%E0%AE%BF%E0%AE%B2%E0%AF%8D+%E0%AE%9A%E0%AF%82%E0%AE%B4%E0%AF%8D%E0%AE%A8%E0%AE%BF%E0%AE%B2%E0%AF%88+%E0%AE%8F%E0%AE%B1%E0%AF%8D%E0%AE%AA%E0%AE%9F%E0%AF%81%E0%AE%AE%E0%AF%8D+%E0%AE%8E%E0%AE%A9%E0%AF%8D%E0%AE%AA%E0%AE%A4%E0%AE%BE%E0%AE%B2%E0%AF%8D+%E0%AE%AA%E0%AE%A3%E0%AE%BF%E0%AE%AF%E0%AF%88%E0%AE%AF%E0%AF%81%E0%AE%AE%E0%AF%8D+%E0%AE%B5%E0%AE%B2%E0%AE%BF+%E0%AE%85%E0%AE%B5%E0%AE%B0%E0%AF%88+%E0%AE%9A%E0%AE%BF%E0%AE%B2+%E0%AE%AA%E0%AF%86%E0%AE%B0%E0%AE%BF%E0%AE%AF+%E0%AE%95%E0%AF%86%E0%AE%BE%E0%AE%B3%E0%AF%8D%E0%AE%AE%E0%AF%81%E0%AE%A4%E0%AE%B2%E0%AF%8D+%E0%AE%AE%E0%AF%81%E0%AE%9F%E0%AE%BF%E0%AE%AF%E0%AF%81%E0%AE%AE%E0%AF%8D.+%E0%AE%85%E0%AE%A4%E0%AF%81+%E0%AE%9A%E0%AE%BF%E0%AE%B2+%E0%AE%A8%E0%AE%A9%E0%AF%8D%E0%AE%AE%E0%AF%88%E0%AE%95%E0%AE%B3%E0%AF%88+%E0%AE%AA%E0%AF%86%E0%AE%B1+%E0%AE%A4%E0%AE%B5%E0%AE%BF%E0%AE%B0%2C+%E0%AE%8E%E0%AE%AA%E0%AF%8D%E0%AE%AA%E0%AF%87%E0%AE%BE%E0%AE%A4%E0%AF%81%E0%AE%AE%E0%AF%8D+%E0%AE%89%E0%AE%B4%E0%AF%88%E0%AE%95%E0%AF%8D%E0%AE%95+%E0%AE%89%E0%AE%9F%E0%AE%B1%E0%AF%8D%E0%AE%AA%E0%AE%AF%E0%AE%BF%E0%AE%B1%E0%AF%8D%E0%AE%9A%E0%AE%BF+%E0%AE%AE%E0%AF%87%E0%AE%B1%E0%AF%8D%E0%AE%95%E0%AF%86%E0%AE%BE%E0%AE%B3%E0%AF%8D%E0%AE%95%E0%AE%BF%E0%AE%B1%E0%AE%A4%E0%AF%81+%E0%AE%8E%E0%AE%99%E0%AF%8D%E0%AE%95%E0%AE%B3%E0%AF%81%E0%AE%95%E0%AF%8D%E0%AE%95%E0%AF%81+%E0%AE%87%E0%AE%A4%E0%AF%81+%E0%AE%92%E0%AE%B0%E0%AF%81+%E0%AE%9A%E0%AE%BF%E0%AE%B1%E0%AE%BF%E0%AE%AF+%E0%AE%89%E0%AE%A4%E0%AE%BE%E0%AE%B0%E0%AE%A3%E0%AE%AE%E0%AF%8D%2C+%E0%AE%8E%E0%AE%9F%E0%AF%81%E0%AE%95%E0%AF%8D%E0%AE%95.+%E0%AE%B0%E0%AE%AF%E0%AE%BF%E0%AE%B2%E0%AF%8D+%E0%AE%8E%E0%AE%A8%E0%AF%8D%E0%AE%A4+%E0%AE%B5%E0%AE%BF%E0%AE%B3%E0%AF%88%E0%AE%B5%E0%AE%BE%E0%AE%95+%E0%AE%87%E0%AE%A9%E0%AF%8D%E0%AE%AA%E0%AE%AE%E0%AF%8D+%E0%AE%86%E0%AE%A9%E0%AF%8D%E0%AE%B2%E0%AF%88%E0%AE%A9%E0%AF%8D+%E0%AE%AA%E0%AE%AF%E0%AE%A9%E0%AF%8D%E0%AE%AA%E0%AE%BE%E0%AE%9F%E0%AF%81%E0%AE%95%E0%AE%B3%E0%AF%8D+%E0%AE%87%E0%AE%B0%E0%AF%81%E0%AE%95%E0%AF%8D%E0%AE%95+%E0%AE%B5%E0%AF%87%E0%AE%A3%E0%AF%8D%E0%AE%9F%E0%AF%81%E0%AE%AE%E0%AF%8D+%E0%AE%A4%E0%AE%AF%E0%AE%BE%E0%AE%B0%E0%AE%BF%E0%AE%95%E0%AF%8D%E0%AE%95%E0%AF%81%E0%AE%AE%E0%AF%8D+%E0%AE%A4%E0%AE%B5%E0%AE%B1%E0%AF%81+%E0%AE%95%E0%AE%A3%E0%AF%8D%E0%AE%9F%E0%AF%81%E0%AE%AA%E0%AE%BF%E0%AE%9F%E0%AE%BF%E0%AE%95%E0%AF%8D%E0%AE%95+%E0%AE%B5%E0%AE%B0%E0%AF%81%E0%AE%AE%E0%AF%8D+%E0%AE%A8%E0%AE%BE%E0%AE%AE%E0%AF%8D+%E0%AE%A4%E0%AE%B1%E0%AF%8D%E0%AE%AA%E0%AF%87%E0%AE%BE%E0%AE%A4%E0%AF%81+%E0%AE%87%E0%AE%B0%E0%AF%81%E0%AE%95%E0%AF%8D%E0%AE%95%E0%AE%BF%E0%AE%B1%E0%AF%87%E0%AE%BE%E0%AE%AE%E0%AF%8D.+%E0%AE%87%E0%AE%A8%E0%AF%8D%E0%AE%A4+%E0%AE%A8%E0%AE%BF%E0%AE%95%E0%AE%B4%E0%AF%8D%E0%AE%B5%E0%AF%81%E0%AE%95%E0%AE%B3%E0%AE%BF%E0%AE%B2%E0%AF%8D+%E0%AE%9A%E0%AF%86%E0%AE%AF%E0%AF%8D%E0%AE%A4%E0%AE%AA%E0%AE%BF%E0%AE%A9%E0%AF%8D+%E0%AE%85%E0%AE%AE%E0%AF%88%E0%AE%AA%E0%AF%8D%E0%AE%AA%E0%AE%BF%E0%AE%A9%E0%AF%8D+%E0%AE%95%E0%AE%A3%E0%AE%95%E0%AF%8D%E0%AE%95%E0%AF%81%2C+%E0%AE%85%E0%AE%B5%E0%AE%B0%E0%AF%8D%E0%AE%95%E0%AE%B3%E0%AF%8D+%E0%AE%A4%E0%AE%B5%E0%AE%B1%E0%AF%81+%E0%AE%B5%E0%AE%BF%E0%AE%9F%E0%AF%8D%E0%AE%9F%E0%AF%81+quae+%E0%AE%AA%E0%AE%9F%E0%AF%8D%E0%AE%9F%E0%AE%B1%E0%AF%88+%E0%AE%A8%E0%AF%80%E0%AE%99%E0%AF%8D%E0%AE%95%E0%AE%B3%E0%AF%8D+%E0%AE%AA%E0%AE%B0%E0%AE%BF%E0%AE%A8%E0%AF%8D%E0%AE%A4%E0%AF%81%E0%AE%B0%E0%AF%88%E0%AE%95%E0%AF%8D%E0%AE%95%E0%AE%BF%E0%AE%B1%E0%AF%87%E0%AE%BE%E0%AE%AE%E0%AF%8D+%E0%AE%AE%E0%AF%86%E0%AE%A9%E0%AF%8D%E0%AE%AE%E0%AF%88%E0%AE%AF%E0%AE%BE%E0%AE%95+%E0%AE%AE%E0%AE%BE%E0%AE%B1%E0%AF%81%E0%AE%AE%E0%AF%8D";
|
||||
|
||||
@Param Type type;
|
||||
|
||||
Object a1;
|
||||
Object a2;
|
||||
Object b1;
|
||||
Object b2;
|
||||
|
||||
Object c1;
|
||||
Object c2;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
a1 = type.newInstance("https://mail.google.com/mail/u/0/?shva=1#inbox");
|
||||
a2 = type.newInstance("https://mail.google.com/mail/u/0/?shva=1#inbox");
|
||||
b1 = type.newInstance("http://developer.android.com/reference/java/net/URI.html");
|
||||
b2 = type.newInstance("http://developer.android.com/reference/java/net/URI.html");
|
||||
|
||||
c1 = type.newInstance("http://developer.android.com/query?q=" + QUERY);
|
||||
// Replace the very last char.
|
||||
c2 = type.newInstance("http://developer.android.com/query?q=" + QUERY.substring(0, QUERY.length() - 3) + "%AF");
|
||||
}
|
||||
|
||||
public void timeEquals(int reps) {
|
||||
for (int i = 0; i < reps; i+=3) {
|
||||
a1.equals(b1);
|
||||
a1.equals(a2);
|
||||
b1.equals(b2);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeHashCode(int reps) {
|
||||
for (int i = 0; i < reps; i+=2) {
|
||||
a1.hashCode();
|
||||
b1.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeEqualsWithHeavilyEscapedComponent(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
c1.equals(c2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.text.DateFormat;
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Benchmarks creation and cloning various expensive objects.
|
||||
*/
|
||||
public class ExpensiveObjectsBenchmark {
|
||||
public void timeNewDateFormatTimeInstance(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||
df.format(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
public void timeClonedDateFormatTimeInstance(int reps) {
|
||||
DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
((DateFormat) df.clone()).format(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
public void timeReusedDateFormatTimeInstance(int reps) {
|
||||
DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
synchronized (df) {
|
||||
df.format(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void timeNewCollator(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
Collator.getInstance(Locale.US);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeClonedCollator(int reps) {
|
||||
Collator c = Collator.getInstance(Locale.US);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
c.clone();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeNewDateFormatSymbols(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
new DateFormatSymbols(Locale.US);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeClonedDateFormatSymbols(int reps) {
|
||||
DateFormatSymbols dfs = new DateFormatSymbols(Locale.US);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
dfs.clone();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeNewDecimalFormatSymbols(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
new DecimalFormatSymbols(Locale.US);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeClonedDecimalFormatSymbols(int reps) {
|
||||
DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
dfs.clone();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeNewNumberFormat(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
NumberFormat.getInstance(Locale.US);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeClonedNumberFormat(int reps) {
|
||||
NumberFormat nf = NumberFormat.getInstance(Locale.US);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
nf.clone();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeNumberFormatTrivialFormatLong(int reps) {
|
||||
NumberFormat nf = NumberFormat.getInstance(Locale.US);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
nf.format(1024L);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeLongToString(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
Long.toString(1024L);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeNumberFormatTrivialFormatDouble(int reps) {
|
||||
NumberFormat nf = NumberFormat.getInstance(Locale.US);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
nf.format(1024.0);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeNewSimpleDateFormat(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
new SimpleDateFormat();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeClonedSimpleDateFormat(int reps) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
sdf.clone();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeNewGregorianCalendar(int reps) {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
new GregorianCalendar();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeClonedGregorianCalendar(int reps) {
|
||||
GregorianCalendar gc = new GregorianCalendar();
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
gc.clone();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public final class FileBenchmark {
|
||||
public void timeFileCreationWithEmptyChild(int nreps) {
|
||||
for (int i = 0; i < nreps; ++i) {
|
||||
new File("/foo", "/");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeFileCreationWithNormalizationNecessary(int nreps) {
|
||||
for (int i = 0; i < nreps; ++i) {
|
||||
new File("/foo//bar//baz//bag", "/baz/");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
public class FloatBenchmark {
|
||||
private float f = 1.2f;
|
||||
private int i = 1067030938;
|
||||
|
||||
public void timeFloatToIntBits(int reps) {
|
||||
int result = 123;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Float.floatToIntBits(f);
|
||||
}
|
||||
if (result != i) {
|
||||
throw new RuntimeException(Integer.toString(result));
|
||||
}
|
||||
}
|
||||
|
||||
public void timeFloatToRawIntBits(int reps) {
|
||||
int result = 123;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Float.floatToRawIntBits(f);
|
||||
}
|
||||
if (result != i) {
|
||||
throw new RuntimeException(Integer.toString(result));
|
||||
}
|
||||
}
|
||||
|
||||
public void timeIntBitsToFloat(int reps) {
|
||||
float result = 123.0f;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Float.intBitsToFloat(i);
|
||||
}
|
||||
if (result != f) {
|
||||
throw new RuntimeException(Float.toString(result) + " " + Float.floatToRawIntBits(result));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.util.Formatter;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Compares Formatter against hand-written StringBuilder code.
|
||||
*/
|
||||
public class FormatterBenchmark {
|
||||
public void timeFormatter_NoFormatting(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Formatter f = new Formatter();
|
||||
f.format("this is a reasonably short string that doesn't actually need any formatting");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeStringBuilder_NoFormatting(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("this is a reasonably short string that doesn't actually need any formatting");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeFormatter_OneInt(int reps) {
|
||||
Integer value = Integer.valueOf(1024); // We're not trying to benchmark boxing here.
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Formatter f = new Formatter();
|
||||
f.format("this is a reasonably short string that has an int %d in it", value);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeFormatter_OneIntArabic(int reps) {
|
||||
Locale arabic = new Locale("ar");
|
||||
Integer value = Integer.valueOf(1024); // We're not trying to benchmark boxing here.
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Formatter f = new Formatter();
|
||||
f.format(arabic, "this is a reasonably short string that has an int %d in it", value);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeStringBuilder_OneInt(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("this is a reasonably short string that has an int ");
|
||||
sb.append(1024);
|
||||
sb.append(" in it");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeFormatter_OneHexInt(int reps) {
|
||||
Integer value = Integer.valueOf(1024); // We're not trying to benchmark boxing here.
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Formatter f = new Formatter();
|
||||
f.format("this is a reasonably short string that has an int %x in it", value);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeStringBuilder_OneHexInt(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("this is a reasonably short string that has an int ");
|
||||
sb.append(Integer.toHexString(1024));
|
||||
sb.append(" in it");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeFormatter_OneFloat(int reps) {
|
||||
Float value = Float.valueOf(10.24f); // We're not trying to benchmark boxing here.
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Formatter f = new Formatter();
|
||||
f.format("this is a reasonably short string that has a float %f in it", value);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeFormatter_OneFloat_dot2f(int reps) {
|
||||
Float value = Float.valueOf(10.24f); // We're not trying to benchmark boxing here.
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Formatter f = new Formatter();
|
||||
f.format("this is a reasonably short string that has a float %.2f in it", value);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeFormatter_TwoFloats(int reps) {
|
||||
Float value = Float.valueOf(10.24f); // We're not trying to benchmark boxing here.
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Formatter f = new Formatter();
|
||||
f.format("this is a reasonably short string that has two floats %f and %f in it", value, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeStringBuilder_OneFloat(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("this is a reasonably short string that has a float ");
|
||||
sb.append(10.24f);
|
||||
sb.append(" in it");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeFormatter_OneString(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
Formatter f = new Formatter();
|
||||
f.format("this is a reasonably short string that has a string %s in it", "hello");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeStringBuilder_OneString(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("this is a reasonably short string that has a string ");
|
||||
sb.append("hello");
|
||||
sb.append(" in it");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Param;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.net.URL;
|
||||
import java.security.Principal;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSessionContext;
|
||||
|
||||
/**
|
||||
* This benchmark makes a real HTTP connection to a handful of hosts and
|
||||
* captures the served certificates as a byte array. It then verifies each
|
||||
* certificate in the benchmark loop, being careful to convert from the
|
||||
* byte[] to the certificate each time. Otherwise the certificate class
|
||||
* caches previous results which skews the results of the benchmark: In practice
|
||||
* each certificate instance is verified once and then released.
|
||||
*/
|
||||
public final class HostnameVerifierBenchmark {
|
||||
|
||||
@Param({"android.clients.google.com",
|
||||
"m.google.com",
|
||||
"www.google.com",
|
||||
"www.amazon.com",
|
||||
"www.ubs.com"}) String host;
|
||||
|
||||
private String hostname;
|
||||
private HostnameVerifier hostnameVerifier;
|
||||
private byte[][] encodedCertificates;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
URL url = new URL("https", host, "/");
|
||||
hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
connection.setHostnameVerifier(new HostnameVerifier() {
|
||||
public boolean verify(String hostname, SSLSession sslSession) {
|
||||
try {
|
||||
encodedCertificates = certificatesToBytes(sslSession.getPeerCertificates());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
HostnameVerifierBenchmark.this.hostname = hostname;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
connection.getInputStream();
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
public void timeVerify(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
final Certificate[] certificates = bytesToCertificates(encodedCertificates);
|
||||
FakeSSLSession sslSession = new FakeSSLSession() {
|
||||
@Override public Certificate[] getPeerCertificates() {
|
||||
return certificates;
|
||||
}
|
||||
};
|
||||
hostnameVerifier.verify(hostname, sslSession);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[][] certificatesToBytes(Certificate[] certificates) throws Exception {
|
||||
byte[][] result = new byte[certificates.length][];
|
||||
for (int i = 0, certificatesLength = certificates.length; i < certificatesLength; i++) {
|
||||
result[i] = certificates[i].getEncoded();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Certificate[] bytesToCertificates(byte[][] encodedCertificates) throws Exception {
|
||||
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
|
||||
Certificate[] result = new Certificate[encodedCertificates.length];
|
||||
for (int i = 0; i < encodedCertificates.length; i++) {
|
||||
result[i] = certificateFactory.generateCertificate(
|
||||
new ByteArrayInputStream(encodedCertificates[i]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class FakeSSLSession implements SSLSession {
|
||||
public int getApplicationBufferSize() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public String getCipherSuite() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public long getCreationTime() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public byte[] getId() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public long getLastAccessedTime() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public Certificate[] getLocalCertificates() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public Principal getLocalPrincipal() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public int getPacketBufferSize() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public javax.security.cert.X509Certificate[] getPeerCertificateChain() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public Certificate[] getPeerCertificates() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public String getPeerHost() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public int getPeerPort() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public Principal getPeerPrincipal() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public String getProtocol() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public SSLSessionContext getSessionContext() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public Object getValue(String name) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public String[] getValueNames() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public void invalidate() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public boolean isValid() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public void putValue(String name, Object value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
public void removeValue(String name) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.net.IDN;
|
||||
|
||||
public class IdnBenchmark {
|
||||
|
||||
public void timeToUnicode(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
IDN.toASCII("fass.de");
|
||||
IDN.toASCII("faß.de");
|
||||
IDN.toASCII("fäß.de");
|
||||
IDN.toASCII("a\u200Cb");
|
||||
IDN.toASCII("öbb.at");
|
||||
IDN.toASCII("abc・日本.co.jp");
|
||||
IDN.toASCII("日本.co.jp");
|
||||
IDN.toASCII("x\u0327\u0301.de");
|
||||
IDN.toASCII("σόλοσ.gr");
|
||||
}
|
||||
}
|
||||
|
||||
public void timeToAscii(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
IDN.toUnicode("xn--fss-qla.de");
|
||||
IDN.toUnicode("xn--n00d.com");
|
||||
IDN.toUnicode("xn--bb-eka.at");
|
||||
IDN.toUnicode("xn--og-09a.de");
|
||||
IDN.toUnicode("xn--53h.de");
|
||||
IDN.toUnicode("xn--iny-zx5a.de");
|
||||
IDN.toUnicode("xn--abc-rs4b422ycvb.co.jp");
|
||||
IDN.toUnicode("xn--wgv71a.co.jp");
|
||||
IDN.toUnicode("xn--x-xbb7i.de");
|
||||
IDN.toUnicode("xn--wxaikc6b.gr");
|
||||
IDN.toUnicode("xn--wxaikc6b.xn--gr-gtd9a1b0g.de");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
public class IntConstantDivisionBenchmark {
|
||||
public int timeDivideIntByConstant2(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result /= 2;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeDivideIntByConstant8(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result /= 8;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeDivideIntByConstant10(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result /= 10;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeDivideIntByConstant100(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result /= 100;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeDivideIntByConstant100_HandOptimized(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result = (int) ((0x51eb851fL * result) >>> 37);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeDivideIntByConstant2048(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result /= 2048;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeDivideIntByVariable2(int reps) {
|
||||
int result = 1;
|
||||
int factor = 2;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result /= factor;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeDivideIntByVariable10(int reps) {
|
||||
int result = 1;
|
||||
int factor = 10;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result /= factor;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
public class IntConstantMultiplicationBenchmark {
|
||||
public int timeMultiplyIntByConstant6(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= 6;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByConstant7(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= 7;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByConstant8(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= 8;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByConstant8_Shift(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result <<= 3;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByConstant10(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= 10;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByConstant10_Shift(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result = (result + (result << 2)) << 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByConstant2047(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= 2047;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByConstant2048(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= 2048;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByConstant2049(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= 2049;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByVariable10(int reps) {
|
||||
int result = 1;
|
||||
int factor = 10;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= factor;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeMultiplyIntByVariable8(int reps) {
|
||||
int result = 1;
|
||||
int factor = 8;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result *= factor;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
public class IntConstantRemainderBenchmark {
|
||||
public int timeRemainderIntByConstant2(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result %= 2;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeRemainderIntByConstant8(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result %= 8;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/*
|
||||
public int timeRemainderIntByConstant10(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result %= 10;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeRemainderIntByConstant100(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result %= 100;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
public int timeRemainderIntByConstant2048(int reps) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result %= 2048;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int timeRemainderIntByVariable2(int reps) {
|
||||
int result = 1;
|
||||
int factor = 2;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result %= factor;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/*
|
||||
public int timeRemainderIntByVariable10(int reps) {
|
||||
int result = 1;
|
||||
int factor = 10;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
result %= factor;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* Copyright (C) 2011 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
public class IntegerBenchmark {
|
||||
public int timeLongSignumBranch(int reps) {
|
||||
int t = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
t += signum1(-i);
|
||||
t += signum1(0);
|
||||
t += signum1(i);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public int timeLongSignumBranchFree(int reps) {
|
||||
int t = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
t += signum2(-i);
|
||||
t += signum2(0);
|
||||
t += signum2(i);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
private static int signum1(long v) {
|
||||
return v < 0 ? -1 : (v == 0 ? 0 : 1);
|
||||
}
|
||||
|
||||
private static int signum2(long v) {
|
||||
return ((int)(v >> 63)) | (int) (-v >>> 63); // Hacker's delight 2-7
|
||||
}
|
||||
|
||||
public int timeLongBitCount_BitSet(int reps) {
|
||||
int t = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
t += pop((long) i);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
private static int pop(long l) {
|
||||
int count = popX(l & 0xffffffffL);
|
||||
count += popX(l >>> 32);
|
||||
return count;
|
||||
}
|
||||
|
||||
private static int popX(long x) {
|
||||
// BEGIN android-note
|
||||
// delegate to Integer.bitCount(i); consider using native code
|
||||
// END android-note
|
||||
x = x - ((x >>> 1) & 0x55555555);
|
||||
x = (x & 0x33333333) + ((x >>> 2) & 0x33333333);
|
||||
x = (x + (x >>> 4)) & 0x0f0f0f0f;
|
||||
x = x + (x >>> 8);
|
||||
x = x + (x >>> 16);
|
||||
return (int) x & 0x0000003f;
|
||||
}
|
||||
|
||||
public int timeLongBitCount_2Int(int reps) {
|
||||
int t = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
t += pop2((long) i);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
private static int pop2(long l) {
|
||||
int count = Integer.bitCount((int) (l & 0xffffffffL));
|
||||
count += Integer.bitCount((int) (l >>> 32));
|
||||
return count;
|
||||
}
|
||||
|
||||
public int timeLongBitCount_Long(int reps) {
|
||||
int t = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
t += Long.bitCount((long) i);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Table for Seal's algorithm for Number of Trailing Zeros. Hacker's Delight
|
||||
* online, Figure 5-18 (http://www.hackersdelight.org/revisions.pdf)
|
||||
* The entries whose value is -1 are never referenced.
|
||||
*/
|
||||
private static final byte[] NTZ_TABLE = {
|
||||
32, 0, 1, 12, 2, 6, -1, 13, 3, -1, 7, -1, -1, -1, -1, 14,
|
||||
10, 4, -1, -1, 8, -1, -1, 25, -1, -1, -1, -1, -1, 21, 27, 15,
|
||||
31, 11, 5, -1, -1, -1, -1, -1, 9, -1, -1, 24, -1, -1, 20, 26,
|
||||
30, -1, -1, -1, -1, 23, -1, 19, 29, -1, 22, 18, 28, 17, 16, -1
|
||||
};
|
||||
|
||||
private static int numberOfTrailingZerosHD(int i) {
|
||||
// Seal's algorithm - Hacker's Delight 5-18
|
||||
i &= -i;
|
||||
i = (i << 4) + i; // x *= 17
|
||||
i = (i << 6) + i; // x *= 65
|
||||
i = (i << 16) - i; // x *= 65535
|
||||
return NTZ_TABLE[i >>> 26];
|
||||
}
|
||||
|
||||
private static int numberOfTrailingZerosOL(int i) {
|
||||
return NTZ_TABLE[((i & -i) * 0x0450FBAF) >>> 26];
|
||||
}
|
||||
|
||||
public int timeNumberOfTrailingZerosHD(int reps) {
|
||||
int t = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
t += numberOfTrailingZerosHD(i);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public int timeNumberOfTrailingZerosOL(int reps) {
|
||||
int t = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
t += numberOfTrailingZerosOL(i);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public int timeIntegerValueOf(int reps) throws Exception {
|
||||
String[] intStrings = new String[]{"0", "1", "12", "123", "1234", "12345",
|
||||
"123456", "1234567", "12345678"};
|
||||
int t = 0;
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
for (int j = 0; j < intStrings.length; ++j) {
|
||||
t += Integer.valueOf(intStrings[j]);
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
public class IntegralToStringBenchmark {
|
||||
|
||||
private static final int SMALL = 12;
|
||||
private static final int MEDIUM = 12345;
|
||||
private static final int LARGE = 12345678;
|
||||
|
||||
public void time_IntegerToString_small(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toString(SMALL);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToString_medium(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toString(MEDIUM);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToString_large(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toString(LARGE);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToString2_small(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toString(SMALL, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToString2_medium(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toString(MEDIUM, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToString2_large(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toString(LARGE, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToString10_small(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toString(SMALL, 10);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToString10_medium(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toString(MEDIUM, 10);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToString10_large(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toString(LARGE, 10);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToString16_small(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toString(SMALL, 16);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToString16_medium(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toString(MEDIUM, 16);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToString16_large(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toString(LARGE, 16);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToBinaryString_small(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toBinaryString(SMALL);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToBinaryString_medium(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toBinaryString(MEDIUM);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToBinaryString_large(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toBinaryString(LARGE);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToHexString_small(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toHexString(SMALL);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToHexString_medium(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toHexString(MEDIUM);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_IntegerToHexString_large(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
Integer.toHexString(LARGE);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_StringBuilder_small(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
new StringBuilder().append(SMALL);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_StringBuilder_medium(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
new StringBuilder().append(MEDIUM);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_StringBuilder_large(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
new StringBuilder().append(LARGE);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_Formatter_small(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
String.format("%d", SMALL);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_Formatter_medium(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
String.format("%d", MEDIUM);
|
||||
}
|
||||
}
|
||||
|
||||
public void time_Formatter_large(int reps) {
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
String.format("%d", LARGE);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
import java.io.File;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
public class JarFileBenchmark {
|
||||
@Param({
|
||||
"/system/framework/core-oj.jar",
|
||||
"/system/priv-app/Phonesky/Phonesky.apk"
|
||||
})
|
||||
private String filename;
|
||||
|
||||
public void time(int reps) throws Exception {
|
||||
File f = new File(filename);
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
JarFile jf = new JarFile(f);
|
||||
Manifest m = jf.getManifest();
|
||||
jf.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (C) 2012 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Param;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
public class KeyPairGeneratorBenchmark {
|
||||
@Param private Algorithm algorithm;
|
||||
|
||||
public enum Algorithm {
|
||||
RSA,
|
||||
DSA,
|
||||
};
|
||||
|
||||
@Param private Implementation implementation;
|
||||
|
||||
public enum Implementation { OpenSSL, BouncyCastle };
|
||||
|
||||
private String generatorAlgorithm;
|
||||
private KeyPairGenerator generator;
|
||||
private SecureRandom random;
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
this.generatorAlgorithm = algorithm.toString();
|
||||
|
||||
final String provider;
|
||||
if (implementation == Implementation.BouncyCastle) {
|
||||
provider = "BC";
|
||||
} else {
|
||||
provider = "AndroidOpenSSL";
|
||||
}
|
||||
|
||||
this.generator = KeyPairGenerator.getInstance(generatorAlgorithm, provider);
|
||||
this.random = SecureRandom.getInstance("SHA1PRNG");
|
||||
this.generator.initialize(1024);
|
||||
}
|
||||
|
||||
public void time(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
KeyPair keyPair = generator.generateKeyPair();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
|
||||
/**
|
||||
* Testing the old canard that looping backwards is faster.
|
||||
*
|
||||
* @author Kevin Bourrillion
|
||||
*/
|
||||
public class LoopingBackwardsBenchmark {
|
||||
@Param({"2", "20", "2000", "20000000"}) int max;
|
||||
|
||||
public int timeForwards(int reps) {
|
||||
int fake = 0;
|
||||
for (int i = 0; i < reps; i++) {
|
||||
for (int j = 0; j < max; j++) {
|
||||
fake += j;
|
||||
}
|
||||
}
|
||||
return fake;
|
||||
}
|
||||
|
||||
public int timeBackwards(int reps) {
|
||||
int fake = 0;
|
||||
for (int i = 0; i < reps; i++) {
|
||||
for (int j = max - 1; j >= 0; j--) {
|
||||
fake += j;
|
||||
}
|
||||
}
|
||||
return fake;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,481 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
/**
|
||||
* Many of these tests are bogus in that the cost will vary wildly depending on inputs.
|
||||
* For _my_ current purposes, that's okay. But beware!
|
||||
*/
|
||||
public class MathBenchmark {
|
||||
private final double d = 1.2;
|
||||
private final float f = 1.2f;
|
||||
private final int i = 1;
|
||||
private final long l = 1L;
|
||||
|
||||
// NOTE: To avoid the benchmarked function from being optimized away, we store the result
|
||||
// and use it as the benchmark's return value. This is good enough for now but may not be in
|
||||
// the future, a smart compiler could determine that the result value will depend on whether
|
||||
// we get into the loop or not and turn the whole loop into an if statement.
|
||||
|
||||
public double timeAbsD(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.abs(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public float timeAbsF(int reps) {
|
||||
float result = f;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.abs(f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int timeAbsI(int reps) {
|
||||
int result = i;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.abs(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public long timeAbsL(int reps) {
|
||||
long result = l;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.abs(l);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeAcos(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.acos(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeAsin(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.asin(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeAtan(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.atan(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeAtan2(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.atan2(3, 4);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeCbrt(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.cbrt(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeCeil(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.ceil(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeCopySignD(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.copySign(d, d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public float timeCopySignF(int reps) {
|
||||
float result = f;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.copySign(f, f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeCopySignD_strict(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = StrictMath.copySign(d, d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public float timeCopySignF_strict(int reps) {
|
||||
float result = f;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = StrictMath.copySign(f, f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeCos(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.cos(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeCosh(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.cosh(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeExp(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.exp(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeExpm1(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.expm1(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeFloor(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.floor(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int timeGetExponentD(int reps) {
|
||||
int result = i;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.getExponent(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int timeGetExponentF(int reps) {
|
||||
int result = i;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.getExponent(f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeHypot(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.hypot(d, d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeIEEEremainder(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.IEEEremainder(d, d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeLog(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.log(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeLog10(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.log10(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeLog1p(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.log1p(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeMaxD(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.max(d, d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public float timeMaxF(int reps) {
|
||||
float result = f;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.max(f, f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int timeMaxI(int reps) {
|
||||
int result = i;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.max(i, i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public long timeMaxL(int reps) {
|
||||
long result = l;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.max(l, l);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeMinD(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.min(d, d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public float timeMinF(int reps) {
|
||||
float result = f;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.min(f, f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int timeMinI(int reps) {
|
||||
int result = i;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.min(i, i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public long timeMinL(int reps) {
|
||||
long result = l;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.min(l, l);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeNextAfterD(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.nextAfter(d, d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public float timeNextAfterF(int reps) {
|
||||
float result = f;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.nextAfter(f, f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeNextUpD(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.nextUp(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public float timeNextUpF(int reps) {
|
||||
float result = f;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.nextUp(f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timePow(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.pow(d, d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeRandom(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.random();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeRint(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.rint(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public long timeRoundD(int reps) {
|
||||
long result = l;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.round(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int timeRoundF(int reps) {
|
||||
int result = i;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.round(f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeScalbD(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.scalb(d, 5);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public float timeScalbF(int reps) {
|
||||
float result = f;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.scalb(f, 5);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeSignumD(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.signum(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public float timeSignumF(int reps) {
|
||||
float result = f;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.signum(f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeSin(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.sin(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeSinh(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.sinh(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeSqrt(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.sqrt(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeTan(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.tan(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeTanh(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.tanh(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeToDegrees(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.toDegrees(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeToRadians(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.toRadians(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public double timeUlpD(int reps) {
|
||||
double result = d;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.ulp(d);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public float timeUlpF(int reps) {
|
||||
float result = f;
|
||||
for (int rep = 0; rep < reps; ++rep) {
|
||||
result = Math.ulp(f);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class MessageDigestBenchmark {
|
||||
|
||||
private static final int DATA_SIZE = 8192;
|
||||
private static final byte[] DATA = new byte[DATA_SIZE];
|
||||
static {
|
||||
for (int i = 0; i < DATA_SIZE; i++) {
|
||||
DATA[i] = (byte)i;
|
||||
}
|
||||
}
|
||||
|
||||
private static final int LARGE_DATA_SIZE = 256 * 1024;
|
||||
private static final byte[] LARGE_DATA = new byte[LARGE_DATA_SIZE];
|
||||
static {
|
||||
for (int i = 0; i < LARGE_DATA_SIZE; i++) {
|
||||
LARGE_DATA[i] = (byte)i;
|
||||
}
|
||||
}
|
||||
|
||||
private static final ByteBuffer SMALL_BUFFER = ByteBuffer.wrap(DATA);
|
||||
private static final ByteBuffer SMALL_DIRECT_BUFFER = ByteBuffer.allocateDirect(DATA_SIZE);
|
||||
static {
|
||||
SMALL_DIRECT_BUFFER.put(DATA);
|
||||
SMALL_DIRECT_BUFFER.flip();
|
||||
}
|
||||
|
||||
private static final ByteBuffer LARGE_BUFFER = ByteBuffer.wrap(LARGE_DATA);
|
||||
private static final ByteBuffer LARGE_DIRECT_BUFFER =
|
||||
ByteBuffer.allocateDirect(LARGE_DATA_SIZE);
|
||||
static {
|
||||
LARGE_DIRECT_BUFFER.put(LARGE_DATA);
|
||||
LARGE_DIRECT_BUFFER.flip();
|
||||
}
|
||||
|
||||
@Param private Algorithm algorithm;
|
||||
|
||||
public enum Algorithm { MD5, SHA1, SHA256, SHA384, SHA512 };
|
||||
|
||||
@Param private Provider provider;
|
||||
|
||||
public enum Provider { AndroidOpenSSL, BC };
|
||||
|
||||
public void time(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
MessageDigest digest = MessageDigest.getInstance(algorithm.toString(),
|
||||
provider.toString());
|
||||
digest.update(DATA, 0, DATA_SIZE);
|
||||
digest.digest();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeLargeArray(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
MessageDigest digest = MessageDigest.getInstance(algorithm.toString(),
|
||||
provider.toString());
|
||||
digest.update(LARGE_DATA, 0, LARGE_DATA_SIZE);
|
||||
digest.digest();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSmallChunkOfLargeArray(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
MessageDigest digest = MessageDigest.getInstance(algorithm.toString(),
|
||||
provider.toString());
|
||||
digest.update(LARGE_DATA, LARGE_DATA_SIZE / 2, DATA_SIZE);
|
||||
digest.digest();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSmallByteBuffer(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
MessageDigest digest = MessageDigest.getInstance(algorithm.toString(),
|
||||
provider.toString());
|
||||
SMALL_BUFFER.position(0);
|
||||
SMALL_BUFFER.limit(SMALL_BUFFER.capacity());
|
||||
digest.update(SMALL_BUFFER);
|
||||
digest.digest();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSmallDirectByteBuffer(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
MessageDigest digest = MessageDigest.getInstance(algorithm.toString(),
|
||||
provider.toString());
|
||||
SMALL_DIRECT_BUFFER.position(0);
|
||||
SMALL_DIRECT_BUFFER.limit(SMALL_DIRECT_BUFFER.capacity());
|
||||
digest.update(SMALL_DIRECT_BUFFER);
|
||||
digest.digest();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeLargeByteBuffer(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
MessageDigest digest = MessageDigest.getInstance(algorithm.toString(),
|
||||
provider.toString());
|
||||
LARGE_BUFFER.position(0);
|
||||
LARGE_BUFFER.limit(LARGE_BUFFER.capacity());
|
||||
digest.update(LARGE_BUFFER);
|
||||
digest.digest();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeLargeDirectByteBuffer(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
MessageDigest digest = MessageDigest.getInstance(algorithm.toString(),
|
||||
provider.toString());
|
||||
LARGE_DIRECT_BUFFER.position(0);
|
||||
LARGE_DIRECT_BUFFER.limit(LARGE_DIRECT_BUFFER.capacity());
|
||||
digest.update(LARGE_DIRECT_BUFFER);
|
||||
digest.digest();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSmallChunkOfLargeByteBuffer(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
MessageDigest digest = MessageDigest.getInstance(algorithm.toString(),
|
||||
provider.toString());
|
||||
LARGE_BUFFER.position(LARGE_BUFFER.capacity() / 2);
|
||||
LARGE_BUFFER.limit(LARGE_BUFFER.position() + DATA_SIZE);
|
||||
digest.update(LARGE_BUFFER);
|
||||
digest.digest();
|
||||
}
|
||||
}
|
||||
|
||||
public void timeSmallChunkOfLargeDirectByteBuffer(int reps) throws Exception {
|
||||
for (int i = 0; i < reps; ++i) {
|
||||
MessageDigest digest = MessageDigest.getInstance(algorithm.toString(),
|
||||
provider.toString());
|
||||
LARGE_DIRECT_BUFFER.position(LARGE_DIRECT_BUFFER.capacity() / 2);
|
||||
LARGE_DIRECT_BUFFER.limit(LARGE_DIRECT_BUFFER.position() + DATA_SIZE);
|
||||
digest.update(LARGE_DIRECT_BUFFER);
|
||||
digest.digest();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.Param;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public final class MutableIntBenchmark {
|
||||
|
||||
enum Kind {
|
||||
ARRAY() {
|
||||
int[] value = new int[1];
|
||||
|
||||
@Override void timeCreate(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
value = new int[] { 5 };
|
||||
}
|
||||
}
|
||||
@Override void timeIncrement(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
value[0]++;
|
||||
}
|
||||
}
|
||||
@Override int timeGet(int reps) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < reps; i++) {
|
||||
sum += value[0];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
},
|
||||
ATOMIC() {
|
||||
AtomicInteger value = new AtomicInteger();
|
||||
|
||||
@Override void timeCreate(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
value = new AtomicInteger(5);
|
||||
}
|
||||
}
|
||||
@Override void timeIncrement(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
value.incrementAndGet();
|
||||
}
|
||||
}
|
||||
@Override int timeGet(int reps) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < reps; i++) {
|
||||
sum += value.intValue();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
};
|
||||
|
||||
abstract void timeCreate(int reps);
|
||||
abstract void timeIncrement(int reps);
|
||||
abstract int timeGet(int reps);
|
||||
}
|
||||
|
||||
@Param Kind kind;
|
||||
|
||||
public void timeCreate(int reps) {
|
||||
kind.timeCreate(reps);
|
||||
}
|
||||
|
||||
public void timeIncrement(int reps) {
|
||||
kind.timeIncrement(reps);
|
||||
}
|
||||
|
||||
public void timeGet(int reps) {
|
||||
kind.timeGet(reps);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
public class NumberFormatBenchmark {
|
||||
|
||||
private static Locale locale = Locale.getDefault(Locale.Category.FORMAT);
|
||||
|
||||
public void time_instantiation(int reps) {
|
||||
for (int i = 0; i < reps; i++) {
|
||||
NumberFormat.getInstance(locale);
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package benchmarks.regression;
|
||||
|
||||
import com.google.caliper.BeforeExperiment;
|
||||
import com.google.caliper.Param;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.Random;
|
||||
|
||||
public class PriorityQueueBenchmark {
|
||||
@Param({"100", "1000", "10000"}) private int queueSize;
|
||||
@Param({"0", "25", "50", "75", "100"}) private int hitRate;
|
||||
|
||||
private PriorityQueue<Integer> pq;
|
||||
private PriorityQueue<Integer> usepq;
|
||||
private List<Integer> seekElements;
|
||||
private Random random = new Random(189279387L);
|
||||
|
||||
@BeforeExperiment
|
||||
protected void setUp() throws Exception {
|
||||
pq = new PriorityQueue<Integer>();
|
||||
usepq = new PriorityQueue<Integer>();
|
||||
seekElements = new ArrayList<Integer>();
|
||||
List<Integer> allElements = new ArrayList<Integer>();
|
||||
int numShared = (int)(queueSize * ((double)hitRate / 100));
|
||||
// the total number of elements we require to engineer a hit rate of hitRate%
|
||||
int totalElements = 2 * queueSize - numShared;
|
||||
for (int i = 0; i < totalElements; i++) {
|
||||
allElements.add(i);
|
||||
}
|
||||
// shuffle these elements so that we get a reasonable distribution of missed elements
|
||||
Collections.shuffle(allElements, random);
|
||||
// add shared elements
|
||||
for (int i = 0; i < numShared; i++) {
|
||||
pq.add(allElements.get(i));
|
||||
seekElements.add(allElements.get(i));
|
||||
}
|
||||
// add priority queue only elements (these won't be touched)
|
||||
for (int i = numShared; i < queueSize; i++) {
|
||||
pq.add(allElements.get(i));
|
||||
}
|
||||
// add non-priority queue elements (these will be misses)
|
||||
for (int i = queueSize; i < totalElements; i++) {
|
||||
seekElements.add(allElements.get(i));
|
||||
}
|
||||
usepq = new PriorityQueue<Integer>(pq);
|
||||
// shuffle again so that elements are accessed in a different pattern than they were
|
||||
// inserted
|
||||
Collections.shuffle(seekElements, random);
|
||||
}
|
||||
|
||||
public boolean timeRemove(int reps) {
|
||||
boolean fake = false;
|
||||
int elementsSize = seekElements.size();
|
||||
// At most allow the queue to empty 10%.
|
||||
int resizingThreshold = queueSize / 10;
|
||||
for (int i = 0; i < reps; i++) {
|
||||
// Reset queue every so often. This will be called more often for smaller
|
||||
// queueSizes, but since a copy is linear, it will also cost proportionally
|
||||
// less, and hopefully it will approximately balance out.
|
||||
if (i % resizingThreshold == 0) {
|
||||
usepq = new PriorityQueue<Integer>(pq);
|
||||
}
|
||||
fake = usepq.remove(seekElements.get(i % elementsSize));
|
||||
}
|
||||
return fake;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue