mirror of
https://github.com/apache/arrow.git
synced 2026-10-28 16:47:19 +08:00
This "leaner" implementation reduces the generated code size of this C++ file from 2307768 bytes to 1192608 bytes in gcc 10.3.0. The benchmarks are also faster (on my avx2 laptop): before ``` ----------------------------------------------------------------------------------------------- Benchmark Time CPU Iterations UserCounters... ----------------------------------------------------------------------------------------------- GreaterArrayArrayInt64/32768/10000 32.1 us 32.1 us 21533 items_per_second=1020.16M/s null_percent=0.01 size=32.768k GreaterArrayArrayInt64/32768/100 32.1 us 32.1 us 21603 items_per_second=1019.27M/s null_percent=1 size=32.768k GreaterArrayArrayInt64/32768/10 32.1 us 32.1 us 21479 items_per_second=1020.82M/s null_percent=10 size=32.768k GreaterArrayArrayInt64/32768/2 32.0 us 32.0 us 21468 items_per_second=1023.12M/s null_percent=50 size=32.768k GreaterArrayArrayInt64/32768/1 32.3 us 32.3 us 21720 items_per_second=1013.44M/s null_percent=100 size=32.768k GreaterArrayArrayInt64/32768/0 31.6 us 31.6 us 21828 items_per_second=1036.94M/s null_percent=0 size=32.768k GreaterArrayScalarInt64/32768/10000 20.8 us 20.8 us 33461 items_per_second=1.57238G/s null_percent=0.01 size=32.768k GreaterArrayScalarInt64/32768/100 20.9 us 20.9 us 33625 items_per_second=1.56611G/s null_percent=1 size=32.768k GreaterArrayScalarInt64/32768/10 20.8 us 20.8 us 33553 items_per_second=1.57338G/s null_percent=10 size=32.768k GreaterArrayScalarInt64/32768/2 20.9 us 20.9 us 33348 items_per_second=1.5687G/s null_percent=50 size=32.768k GreaterArrayScalarInt64/32768/1 20.9 us 20.9 us 33419 items_per_second=1.56879G/s null_percent=100 size=32.768k GreaterArrayScalarInt64/32768/0 20.5 us 20.5 us 34116 items_per_second=1.59837G/s null_percent=0 size=32.768k ``` after ``` ----------------------------------------------------------------------------------------------- Benchmark Time CPU Iterations UserCounters... ----------------------------------------------------------------------------------------------- GreaterArrayArrayInt64/32768/10000 18.1 us 18.1 us 38751 items_per_second=1.81199G/s null_percent=0.01 size=32.768k GreaterArrayArrayInt64/32768/100 17.5 us 17.5 us 39374 items_per_second=1.86821G/s null_percent=1 size=32.768k GreaterArrayArrayInt64/32768/10 19.0 us 19.0 us 33941 items_per_second=1.72066G/s null_percent=10 size=32.768k GreaterArrayArrayInt64/32768/2 18.0 us 18.0 us 39589 items_per_second=1.81817G/s null_percent=50 size=32.768k GreaterArrayArrayInt64/32768/1 18.1 us 18.1 us 39061 items_per_second=1.80719G/s null_percent=100 size=32.768k GreaterArrayArrayInt64/32768/0 17.5 us 17.5 us 39813 items_per_second=1.87031G/s null_percent=0 size=32.768k GreaterArrayScalarInt64/32768/10000 16.3 us 16.3 us 42281 items_per_second=2.01525G/s null_percent=0.01 size=32.768k GreaterArrayScalarInt64/32768/100 16.5 us 16.5 us 42266 items_per_second=1.98195G/s null_percent=1 size=32.768k GreaterArrayScalarInt64/32768/10 16.5 us 16.5 us 41872 items_per_second=1.98615G/s null_percent=10 size=32.768k GreaterArrayScalarInt64/32768/2 16.3 us 16.3 us 42130 items_per_second=2.00447G/s null_percent=50 size=32.768k GreaterArrayScalarInt64/32768/1 16.2 us 16.2 us 42391 items_per_second=2.02296G/s null_percent=100 size=32.768k GreaterArrayScalarInt64/32768/0 15.9 us 15.9 us 43498 items_per_second=2.0614G/s null_percent=0 size=32.768k ``` Authored-by: Wes McKinney <wesm@apache.org> Signed-off-by: Wes McKinney <wesm@apache.org>
122 lines
4.0 KiB
Python
122 lines
4.0 KiB
Python
#
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
# this work for additional information regarding copyright ownership.
|
|
# The ASF licenses this file to You 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 subprocess as sbp
|
|
import sys
|
|
|
|
try:
|
|
import pandas as pd
|
|
HAVE_PANDAS = True
|
|
except ImportError:
|
|
HAVE_PANDAS = False
|
|
|
|
SYMBOL_FILTERS = {
|
|
'std::chrono::duration': 'duration',
|
|
'std::__cxx11::basic_string': 'std::string',
|
|
'arrow::ArrayData': 'ArrayData',
|
|
'arrow::ArraySpan': 'ArraySpan',
|
|
'arrow::Datum': 'Datum',
|
|
'arrow::Scalar': 'Scalar',
|
|
'arrow::Status': 'Status',
|
|
'arrow::Type': 'Type',
|
|
'arrow::TimestampType': 'TsT',
|
|
'arrow::BinaryType': 'BinaryT',
|
|
'arrow::BooleanType': 'BoolT',
|
|
'arrow::StringType': 'StringT',
|
|
'arrow::LargeStringType': 'LStringT',
|
|
'arrow::DoubleType': 'DoubleT',
|
|
'arrow::FloatType': 'FloatT',
|
|
'arrow::Int64Type': 'Int64T',
|
|
'arrow::UInt64Type': 'UInt64T',
|
|
'arrow::LargeListType': 'LListT',
|
|
'arrow::ListType': 'ListT',
|
|
'arrow::FixedSizeListType': 'FSLT',
|
|
'arrow::compute::': 'ac::',
|
|
'ac::internal::': '',
|
|
'arrow::internal::': 'ai::',
|
|
'(anonymous namespace)::': '',
|
|
'internal::applicator::': '',
|
|
'internal::CastFunctor': 'CastFunctor',
|
|
'ac::KernelContext*': 'C*',
|
|
'ArrayData const&': 'A&',
|
|
'ArraySpan const&': 'A&',
|
|
'ArrayData*': 'O*',
|
|
'Scalar const&': 'S&',
|
|
'Datum const&': 'V&',
|
|
'Datum*': 'O*',
|
|
'ac::ExecBatch const&': 'B&',
|
|
'ac::ExecSpan const&': 'B&',
|
|
'ac::ExecValue const&': 'V&',
|
|
'ac::ExecResult*': 'O*',
|
|
'Type::type': 'T',
|
|
}
|
|
|
|
|
|
def filter_symbol(symbol_name):
|
|
for token, replacement in SYMBOL_FILTERS.items():
|
|
symbol_name = symbol_name.replace(token, replacement)
|
|
return symbol_name
|
|
|
|
|
|
def get_symbols_and_sizes(object_file):
|
|
cmd = f"nm --print-size --size-sort {object_file} | c++filt"
|
|
output = sbp.check_output(cmd, shell=True).decode('utf-8')
|
|
symbol_sizes = []
|
|
for x in output.split('\n'):
|
|
if len(x) == 0:
|
|
continue
|
|
_, hex_size, _, symbol_name = x.split(' ', 3)
|
|
symbol_name = filter_symbol(symbol_name)
|
|
symbol_sizes.append((symbol_name, int(hex_size, 16)))
|
|
return dict(symbol_sizes)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
base, contender = sys.argv[1], sys.argv[2]
|
|
|
|
base_results = get_symbols_and_sizes(base)
|
|
contender_results = get_symbols_and_sizes(contender)
|
|
|
|
all_symbols = set(base_results.keys()) | set(contender_results.keys())
|
|
|
|
diff_table = []
|
|
for name in all_symbols:
|
|
if name in base_results and name in contender_results:
|
|
base_size = base_results[name]
|
|
contender_size = contender_results[name]
|
|
elif name in base_results:
|
|
base_size = base_results[name]
|
|
contender_size = 0
|
|
else:
|
|
base_size = 0
|
|
contender_size = contender_results[name]
|
|
diff = contender_size - base_size
|
|
diff_table.append((name, base_size, contender_size, diff))
|
|
diff_table.sort(key=lambda x: x[3])
|
|
|
|
if HAVE_PANDAS:
|
|
diff = pd.DataFrame.from_records(diff_table,
|
|
columns=['symbol', 'base',
|
|
'contender', 'diff'])
|
|
pd.options.display.max_rows = 1000
|
|
pd.options.display.max_colwidth = 150
|
|
print(diff[diff['diff'] < - 700])
|
|
print(diff[diff['diff'] > 700])
|
|
else:
|
|
# TODO
|
|
pass
|