IDE perf tests for K/N: keep Kotlin & Gradle versions in *.properties
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import kotlinx.cinterop.ByteVar
|
||||
import kotlinx.cinterop.allocArray
|
||||
import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.toKString
|
||||
import kotlinx.cli.ArgParser
|
||||
import kotlinx.cli.ArgType
|
||||
import kotlinx.cli.required
|
||||
import platform.posix.fclose
|
||||
import platform.posix.fgets
|
||||
import platform.posix.fopen
|
||||
import platform.posix.perror
|
||||
import kotlin.collections.set
|
||||
|
||||
private fun parseLine(line: String, separator: Char) : List<String> {
|
||||
val result = mutableListOf<String>()
|
||||
val builder = StringBuilder()
|
||||
var quotes = 0
|
||||
for (ch in line) {
|
||||
when {
|
||||
ch == '\"' -> {
|
||||
quotes++
|
||||
builder.append(ch)
|
||||
}
|
||||
(ch == '\n') || (ch == '\r') -> {}
|
||||
(ch == separator) && (quotes % 2 == 0) -> {
|
||||
result.add(builder.toString())
|
||||
builder.setLength(0)
|
||||
}
|
||||
else -> builder.append(ch)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val argParser = ArgParser("csvparser")
|
||||
val fileName by argParser.argument(ArgType.String, description = "CSV file")
|
||||
val column by argParser.option(ArgType.Int, description = "Column to parse").required()
|
||||
val count by argParser.option(ArgType.Int, description = "Count of lines to parse").required()
|
||||
argParser.parse(args)
|
||||
|
||||
val file = fopen(fileName, "r")
|
||||
if (file == null) {
|
||||
perror("cannot open input file $fileName")
|
||||
return
|
||||
}
|
||||
|
||||
val keyValue = mutableMapOf<String, Int>()
|
||||
|
||||
try {
|
||||
memScoped {
|
||||
val bufferLength = 64 * 1024
|
||||
val buffer = allocArray<ByteVar>(bufferLength)
|
||||
|
||||
for (i in 1..count) {
|
||||
val nextLine = fgets(buffer, bufferLength, file)?.toKString()
|
||||
if (nextLine == null || nextLine.isEmpty()) break
|
||||
|
||||
val records = parseLine(nextLine, ',')
|
||||
val key = records[column]
|
||||
val current = keyValue[key] ?: 0
|
||||
keyValue[key] = current + 1
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fclose(file)
|
||||
}
|
||||
|
||||
keyValue.forEach {
|
||||
println("${it.key} -> ${it.value}")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import kotlinx.cinterop.ByteVar
|
||||
import kotlinx.cinterop.allocArray
|
||||
import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.toKString
|
||||
import kotlinx.cli.ArgParser
|
||||
import kotlinx.cli.ArgType
|
||||
import kotlinx.cli.required
|
||||
import platform.posix.fclose
|
||||
import platform.posix.fgets
|
||||
import platform.posix.fopen
|
||||
import platform.posix.perror
|
||||
import kotlin.collections.set
|
||||
|
||||
private fun parseLine(line: String, separator: Char) : List<String> {
|
||||
val result = mutableListOf<String>()
|
||||
val builder = StringBuilder()
|
||||
var quotes = 0
|
||||
for (ch in line) {
|
||||
when {
|
||||
ch == '\"' -> {
|
||||
quotes++
|
||||
builder.append(ch)
|
||||
}
|
||||
(ch == '\n') || (ch == '\r') -> {}
|
||||
(ch == separator) && (quotes % 2 == 0) -> {
|
||||
result.add(builder.toString())
|
||||
builder.setLength(0)
|
||||
}
|
||||
else -> builder.append(ch)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val argParser = ArgParser("csvparser")
|
||||
val fileName by argParser.argument(ArgType.String, description = "CSV file")
|
||||
val column by argParser.option(ArgType.Int, description = "Column to parse").required()
|
||||
val count by argParser.option(ArgType.Int, description = "Count of lines to parse").required()
|
||||
argParser.parse(args)
|
||||
|
||||
val file = fopen(fileName, "r")
|
||||
if (file == null) {
|
||||
perror("cannot open input file $fileName")
|
||||
return
|
||||
}
|
||||
|
||||
val keyValue = mutableMapOf<String, Int>()
|
||||
|
||||
try {
|
||||
memScoped {
|
||||
val bufferLength = 64 * 1024
|
||||
val buffer = allocArray<ByteVar>(bufferLength)
|
||||
|
||||
for (i in 1..count) {
|
||||
val nextLine = fgets(buffer, bufferLength, file)?.toKString()
|
||||
if (nextLine == null || nextLine.isEmpty()) break
|
||||
|
||||
val records = parseLine(nextLine, ',')
|
||||
val key = records[column]
|
||||
val current = keyValue[key] ?: 0
|
||||
keyValue[key] = current + 1
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fclose(file)
|
||||
}
|
||||
|
||||
keyValue.forEach {
|
||||
println("${it.key} -> ${it.value}")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import kotlinx.cinterop.ByteVar
|
||||
import kotlinx.cinterop.allocArray
|
||||
import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.toKString
|
||||
import kotlinx.cli.ArgParser
|
||||
import kotlinx.cli.ArgType
|
||||
import kotlinx.cli.required
|
||||
import platform.posix.fclose
|
||||
import platform.posix.fgets
|
||||
import platform.posix.fopen
|
||||
import platform.posix.perror
|
||||
import kotlin.collections.set
|
||||
|
||||
private fun parseLine(line: String, separator: Char) : List<String> {
|
||||
val result = mutableListOf<String>()
|
||||
val builder = StringBuilder()
|
||||
var quotes = 0
|
||||
for (ch in line) {
|
||||
when {
|
||||
ch == '\"' -> {
|
||||
quotes++
|
||||
builder.append(ch)
|
||||
}
|
||||
(ch == '\n') || (ch == '\r') -> {}
|
||||
(ch == separator) && (quotes % 2 == 0) -> {
|
||||
result.add(builder.toString())
|
||||
builder.setLength(0)
|
||||
}
|
||||
else -> builder.append(ch)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val argParser = ArgParser("csvparser")
|
||||
val fileName by argParser.argument(ArgType.String, description = "CSV file")
|
||||
val column by argParser.option(ArgType.Int, description = "Column to parse").required()
|
||||
val count by argParser.option(ArgType.Int, description = "Count of lines to parse").required()
|
||||
argParser.parse(args)
|
||||
|
||||
val file = fopen(fileName, "r")
|
||||
if (file == null) {
|
||||
perror("cannot open input file $fileName")
|
||||
return
|
||||
}
|
||||
|
||||
val keyValue = mutableMapOf<String, Int>()
|
||||
|
||||
try {
|
||||
memScoped {
|
||||
val bufferLength = 64 * 1024
|
||||
val buffer = allocArray<ByteVar>(bufferLength)
|
||||
|
||||
for (i in 1..count) {
|
||||
val nextLine = fgets(buffer, bufferLength, file)?.toKString()
|
||||
if (nextLine == null || nextLine.isEmpty()) break
|
||||
|
||||
val records = parseLine(nextLine, ',')
|
||||
val key = records[column]
|
||||
val current = keyValue[key] ?: 0
|
||||
keyValue[key] = current + 1
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fclose(file)
|
||||
}
|
||||
|
||||
keyValue.forEach {
|
||||
println("${it.key} -> ${it.value}")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user